Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

New Snippet Added #6

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
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
40 changes: 40 additions & 0 deletions README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,43 @@ import nltk
nltk.download('punkt')
nltk.download('averaged_perceptron_tagger')
```

## Python Snippets

### Anagrams
An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
```
from collections import Counter
def anagram(first, second):
return Counter(first) == Counter(second)
anagram("abcd3", "3acdb") # True
```
### Memory
This snippet can be used to check the memory usage of an object.
```
import sys

variable = 30
print(sys.getsizeof(variable)) # 24
```
### Print a string N times
This snippet can be used to print a string n times without having to use loops to do it.
```
n = 2
s ="Programming"
print(s * n) # ProgrammingProgramming
```
### Chunk
This method chunks a list into smaller lists of a specified size.
```
def chunk(list, size):
return [list[i:i+size] for i in range(0,len(list), size)]
```
### Get vowels
This method gets vowels (‘a’, ‘e’, ‘i’, ‘o’, ‘u’) found in a string.
```
def get_vowels(string):
return [each for each in string if each in 'aeiou']
get_vowels('foobar') # ['o', 'o', 'a']
get_vowels('gym') # []
```

AltStyle によって変換されたページ (->オリジナル) /