-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from MinerMinerMods/main
Improved Quality of Python Snippets, fixed issue with CONTRIBUTING.md
- Loading branch information
Showing
8 changed files
with
56 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
snippets/python/string-manipulation/convert-string-to-ascii.md
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
snippets/python/string-manipulation/convert-string-to-unicode.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
``` |
2 changes: 1 addition & 1 deletion
2
...anipulation/remove-specific-characters.md → .../string-manipulation/remove-characters.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
title: Truncate | ||
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 ' | ||
``` |