Skip to content

Improved Quality of Python Snippets, fixed issue with CONTRIBUTING.md #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 7, 2025
Merged
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ If your function doesn't return anything just show how to use it. If the result

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

If any answer is yes, then your snippet will most likely get rejected.
Expand Down
14 changes: 0 additions & 14 deletions snippets/python/string-manipulation/convert-string-to-ascii.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Convert String to Unicode
description: Converts a string into its Unicode representation.
author: axorax
tags: string,ascii,unicode,convert
---

```py
def string_to_unicode(s):
return [ord(char) for char in s]

# Usage:
string_to_unicode('hello') # Returns: [104, 101, 108, 108, 111]
```
File renamed without changes.
4 changes: 2 additions & 2 deletions snippets/python/string-manipulation/reverse-string.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ tags: string,reverse
---

```py
def reverse_string(s):
return s[::-1]
def reverse_string(s:str) -> str:
return s[::-1]

# Usage:
reverse_string('hello') # Returns: 'olleh'
Expand Down
14 changes: 0 additions & 14 deletions snippets/python/string-manipulation/truncate-string.md

This file was deleted.

16 changes: 16 additions & 0 deletions snippets/python/string-manipulation/truncate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: Truncate String
description: Truncates a string to a specified length and a toggleable truncation notation.
author: axorax
contributors: MinerMinerMods
tags: string,truncate
---

```py
def truncate(s:str, length:int, suffix:bool = True) -> str :
return (s[:length] + ("..." if suffix else "")) if len(s) > length else s

# Usage:
truncate('This is a long string', 10) # Returns: 'This is a ...'
truncate('This is a long string', 10, False) # Returns: 'This is a '
```