Skip to content

Instantly share code, notes, and snippets.

@Frankie-B
Forked from magicpotion/CodeSnippets
Created March 1, 2022 16:02
Show Gist options
  • Save Frankie-B/648d0bfa366269c8a786a2211deddb69 to your computer and use it in GitHub Desktop.
Save Frankie-B/648d0bfa366269c8a786a2211deddb69 to your computer and use it in GitHub Desktop.
Code Snippets
Code Snippets
```
getIntFromStr := func(str string, def int) int {
number, err := strconv.Atoi(strings.TrimSpace(str))
if err != nil {
return def
}
return number
}
```
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'])];
"""
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