|
535 | 535 | "code": "def snake_to_camel(s):\n parts = s.split('_')\n return parts[0] + ''.join(word.capitalize() for word in parts[1:])\n\n# Usage:\nsnake_to_camel('hello_world') # Returns: 'helloWorld'\n"
|
536 | 536 | },
|
537 | 537 | {
|
538 |
| - "title": "Convert String to ASCII", |
539 |
| - "description": "Converts a string into its ASCII representation.", |
| 538 | + "title": "Convert String to Unicode", |
| 539 | + "description": "Converts a string into its Unicode representation.", |
540 | 540 | "author": "axorax",
|
541 | 541 | "tags": [
|
542 | 542 | "string",
|
543 | 543 | "ascii",
|
| 544 | + "unicode", |
544 | 545 | "convert"
|
545 | 546 | ],
|
546 | 547 | "contributors": [],
|
547 |
| - "code": "def string_to_ascii(s):\n return [ord(char) for char in s]\n\n# Usage:\nstring_to_ascii('hello') # Returns: [104, 101, 108, 108, 111]\n" |
| 548 | + "code": "def string_to_unicode(s):\n return [ord(char) for char in s]\n\n# Usage:\nstring_to_unicode('hello') # Returns: [104, 101, 108, 108, 111]\n" |
548 | 549 | },
|
549 | 550 | {
|
550 | 551 | "title": "Count Character Frequency",
|
|
626 | 627 | "contributors": [],
|
627 | 628 | "code": "import random\nimport string\n\ndef random_string(length):\n letters_and_digits = string.ascii_letters + string.digits\n return ''.join(random.choice(letters_and_digits) for _ in range(length))\n\n# Usage:\nrandom_string(10) # Results: Random 10-character string\n"
|
628 | 629 | },
|
| 630 | + { |
| 631 | + "title": "Remove Characters", |
| 632 | + "description": "Removes specific characters from a string.", |
| 633 | + "author": "axorax", |
| 634 | + "tags": [ |
| 635 | + "string", |
| 636 | + "remove", |
| 637 | + "characters" |
| 638 | + ], |
| 639 | + "contributors": [], |
| 640 | + "code": "def remove_chars(s, chars):\n return ''.join(c for c in s if c not in chars)\n\n# Usage:\nremove_chars('hello world', 'eo') # Returns: 'hll wrld'\n" |
| 641 | + }, |
629 | 642 | {
|
630 | 643 | "title": "Remove Duplicate Characters",
|
631 | 644 | "description": "Removes duplicate characters from a string while maintaining the order.",
|
|
650 | 663 | "contributors": [],
|
651 | 664 | "code": "import string\n\ndef remove_punctuation(s):\n return s.translate(str.maketrans('', '', string.punctuation))\n\n# Usage:\nremove_punctuation('Hello, World!') # Returns: 'Hello World'\n"
|
652 | 665 | },
|
653 |
| - { |
654 |
| - "title": "Remove Specific Characters", |
655 |
| - "description": "Removes specific characters from a string.", |
656 |
| - "author": "axorax", |
657 |
| - "tags": [ |
658 |
| - "string", |
659 |
| - "remove", |
660 |
| - "characters" |
661 |
| - ], |
662 |
| - "contributors": [], |
663 |
| - "code": "def remove_chars(s, chars):\n return ''.join(c for c in s if c not in chars)\n\n# Usage:\nremove_chars('hello world', 'eo') # Returns: 'hll wrld'\n" |
664 |
| - }, |
665 | 666 | {
|
666 | 667 | "title": "Remove Whitespace",
|
667 | 668 | "description": "Removes all whitespace from a string.",
|
|
683 | 684 | "reverse"
|
684 | 685 | ],
|
685 | 686 | "contributors": [],
|
686 |
| - "code": "def reverse_string(s):\n return s[::-1]\n\n# Usage:\nreverse_string('hello') # Returns: 'olleh'\n" |
| 687 | + "code": "def reverse_string(s:str) -> str:\n return s[::-1]\n\n# Usage:\nreverse_string('hello') # Returns: 'olleh'\n" |
687 | 688 | },
|
688 | 689 | {
|
689 | 690 | "title": "Split Camel Case",
|
|
698 | 699 | "code": "import re\n\ndef split_camel_case(s):\n return ' '.join(re.findall(r'[A-Z][a-z]*|[a-z]+', s))\n\n# Usage:\nsplit_camel_case('camelCaseString') # Returns: 'camel Case String'\n"
|
699 | 700 | },
|
700 | 701 | {
|
701 |
| - "title": "Truncate String", |
702 |
| - "description": "Truncates a string to a specified length and adds an ellipsis.", |
| 702 | + "title": "Truncate", |
| 703 | + "description": "Truncates a string to a specified length and a toggleable truncation notation.", |
703 | 704 | "author": "axorax",
|
704 | 705 | "tags": [
|
705 | 706 | "string",
|
706 | 707 | "truncate"
|
707 | 708 | ],
|
708 |
| - "contributors": [], |
709 |
| - "code": "def truncate_string(s, length):\n return s[:length] + '...' if len(s) > length else s\n\n# Usage:\ntruncate_string('This is a long string', 10) # Returns: 'This is a ...'\n" |
| 709 | + "contributors": [ |
| 710 | + "MinerMinerMods" |
| 711 | + ], |
| 712 | + "code": "def truncate(s:str, length:int, suffix:bool = True) -> str :\n return (s[:length] + (\"...\" if suffix else \"\")) if len(s) > length else s\n\n# Usage:\ntruncate('This is a long string', 10) # Returns: 'This is a ...'\ntruncate('This is a long string', 10, False) # Returns: 'This is a '\n" |
710 | 713 | }
|
711 | 714 | ]
|
712 | 715 | }
|
|
0 commit comments