Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 52e7c9c

Browse files
Merge pull request #193 from MinerMinerMods/main
Improved Quality of Python Snippets, fixed issue with CONTRIBUTING.md
2 parents 9181837 + 4a7da2b commit 52e7c9c

File tree

8 files changed

+56
-51
lines changed

8 files changed

+56
-51
lines changed

‎CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ If your function doesn't return anything just show how to use it. If the result
6565

6666
To ensure your snippet isn’t refused, consider these questions:
6767
- **Does the standard library of my language provide an easy way of doing this ?**
68-
- **Does that snippet have a real, and practical use case ?**
68+
- **Does that snippet not have a real, and practical use case ?**
6969
- **Could it be split into separate parts to be better understood ?**
7070

7171
If any answer is yes, then your snippet will most likely get rejected.

‎public/consolidated/python.json

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -535,16 +535,17 @@
535535
"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"
536536
},
537537
{
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.",
540540
"author": "axorax",
541541
"tags": [
542542
"string",
543543
"ascii",
544+
"unicode",
544545
"convert"
545546
],
546547
"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"
548549
},
549550
{
550551
"title": "Count Character Frequency",
@@ -626,6 +627,18 @@
626627
"contributors": [],
627628
"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"
628629
},
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+
},
629642
{
630643
"title": "Remove Duplicate Characters",
631644
"description": "Removes duplicate characters from a string while maintaining the order.",
@@ -650,18 +663,6 @@
650663
"contributors": [],
651664
"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"
652665
},
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-
},
665666
{
666667
"title": "Remove Whitespace",
667668
"description": "Removes all whitespace from a string.",
@@ -683,7 +684,7 @@
683684
"reverse"
684685
],
685686
"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"
687688
},
688689
{
689690
"title": "Split Camel Case",
@@ -698,15 +699,17 @@
698699
"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"
699700
},
700701
{
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.",
703704
"author": "axorax",
704705
"tags": [
705706
"string",
706707
"truncate"
707708
],
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"
710713
}
711714
]
712715
}

‎snippets/python/string-manipulation/convert-string-to-ascii.md

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: Convert String to Unicode
3+
description: Converts a string into its Unicode representation.
4+
author: axorax
5+
tags: string,ascii,unicode,convert
6+
---
7+
8+
```py
9+
def string_to_unicode(s):
10+
return [ord(char) for char in s]
11+
12+
# Usage:
13+
string_to_unicode('hello') # Returns: [104, 101, 108, 108, 111]
14+
```

‎snippets/python/string-manipulation/remove-specific-characters.md renamed to ‎snippets/python/string-manipulation/remove-characters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Remove Specific Characters
2+
title: Remove Characters
33
description: Removes specific characters from a string.
44
author: axorax
55
tags: string,remove,characters

‎snippets/python/string-manipulation/reverse-string.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ tags: string,reverse
66
---
77

88
```py
9-
def reverse_string(s):
9+
def reverse_string(s:str) -> str:
1010
return s[::-1]
1111

1212
# Usage:

‎snippets/python/string-manipulation/truncate-string.md

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Truncate
3+
description: Truncates a string to a specified length and a toggleable truncation notation.
4+
author: axorax
5+
contributors: MinerMinerMods
6+
tags: string,truncate
7+
---
8+
9+
```py
10+
def truncate(s:str, length:int, suffix:bool = True) -> str :
11+
return (s[:length] + ("..." if suffix else "")) if len(s) > length else s
12+
13+
# Usage:
14+
truncate('This is a long string', 10) # Returns: 'This is a ...'
15+
truncate('This is a long string', 10, False) # Returns: 'This is a '
16+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /