-
-
Save Frankie-B/648d0bfa366269c8a786a2211deddb69 to your computer and use it in GitHub Desktop.
Code Snippets
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
Code Snippets |
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
``` | |
getIntFromStr := func(str string, def int) int { | |
number, err := strconv.Atoi(strings.TrimSpace(str)) | |
if err != nil { | |
return def | |
} | |
return number | |
} | |
``` |
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
array.includes(object1) = [1, 2, 3].includes(2) | |
[[1, 2, 3],[4, 5, 6],[7,[8,9]].flat(2) === [1, 2, 3, 4, 5, 6, 7, 8, 9] | |
var unique_set = [...new Set(['Opel', 'Bugatti', 'Opel', 'Ferrari', 'Ferrari', 'Opel'])]; |
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
""" | |
Find Close Matches of a Word | |
""" | |
import difflib | |
difflib.get_close_matches('appel', ['ape', 'apple', 'peach', 'puppy'], n=2) | |
# returns ['apple', 'ape'] | |
""" | |
Skipping Begining of Comment File | |
""" | |
string_from_file = """ | |
// Author: ... | |
Actual content... | |
""" | |
import itertools | |
for line in itertools.dropwhile(lambda line: line.startswith("//"), string_from_file.split("\n")): | |
print(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment