Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

14 changes: 14 additions & 0 deletions snippets/python/string-manipulation/convert-string-to-unicode.md
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]
```
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 '
```