Merge branch 'master' into master
This commit is contained in:
@ -39,7 +39,7 @@ Here's what you can do to help:
|
|||||||
- You can start creating a new snippet, by using the [snippet template](snippet_template.md) to format your snippets.
|
- You can start creating a new snippet, by using the [snippet template](snippet_template.md) to format your snippets.
|
||||||
- Updating the README.md file should only be done by altering the scripts in the **scripts** folder or altering their relative static parts in the **static-parts** folder.
|
- Updating the README.md file should only be done by altering the scripts in the **scripts** folder or altering their relative static parts in the **static-parts** folder.
|
||||||
- You may tag your snippet in tag_databse although it is _not_ necessary.
|
- You may tag your snippet in tag_databse although it is _not_ necessary.
|
||||||
- You may add your name as `[Name][@github_username]` to the contributor database. If the snippet already exists and you are making changes to it you can add your name at the laste seperated by a comma.
|
- You may add your name as `[Name][@github_username]` to the contributor database. If the snippet already exists and you are making changes to it you can add your name at the last seperated by a comma.
|
||||||
<!--
|
<!--
|
||||||
### Additional guidelines and conventions regarding snippets
|
### Additional guidelines and conventions regarding snippets
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ max_n:[Rohit Tanwar](@kriadmin)
|
|||||||
min_n:[Rohit Tanwar](@kriadmin)
|
min_n:[Rohit Tanwar](@kriadmin)
|
||||||
shuffle:[Rohit Tanwar](@kriadmin)
|
shuffle:[Rohit Tanwar](@kriadmin)
|
||||||
spread:[Rohit Tanwar](@kriadmin)
|
spread:[Rohit Tanwar](@kriadmin)
|
||||||
zip:[Rohit Tanwar](@kriadmin)
|
zip:[Rohit Tanwar](@kriadmin),[Leonardo Galdino](@LeonardoGaldino)
|
||||||
byte_size:[Rohit Tanwar](@kriadmin)
|
byte_size:[Rohit Tanwar](@kriadmin)
|
||||||
capitalize:[Rohit Tanwar](@kriadmin)
|
capitalize:[Rohit Tanwar](@kriadmin)
|
||||||
capitalize_every_word:[Rohit Tanwar](@kriadmin)
|
capitalize_every_word:[Rohit Tanwar](@kriadmin)
|
||||||
@ -25,6 +25,6 @@ insertion_sort:[Meet Zaveri](@meetzaveri),[Rohit Tanwar](@kriadmin)
|
|||||||
difference_by:[Rohit Tanwar](@kriadmin)
|
difference_by:[Rohit Tanwar](@kriadmin)
|
||||||
bubble_sort: [Shobhit Sachan](@sachans)
|
bubble_sort: [Shobhit Sachan](@sachans)
|
||||||
has_duplicates: [Rob-Rychs](@Rob-Rychs)
|
has_duplicates: [Rob-Rychs](@Rob-Rychs)
|
||||||
keys_only: [Rob-Rychs](@Rob-Rychs)
|
keys_only: [Rob-Rychs](@Rob-Rychs),[Matteo Veraldi](@mattveraldi)
|
||||||
values_only: [Rob-Rychs](@Rob-Rychs)
|
values_only: [Rob-Rychs](@Rob-Rychs)
|
||||||
all_unique: [Rob-Rychs](@Rob-Rychs)
|
all_unique: [Rob-Rychs](@Rob-Rychs)
|
||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Returns the length of a string in bytes.
|
Returns the length of a string in bytes.
|
||||||
|
|
||||||
`utf-8` encodes a given string and find its length.
|
`utf-8` encodes a given string, then `len` finds the length of the encoded string.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def byte_size(string):
|
def byte_size(string):
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
:information_source: Already implemented via `list.count()`.
|
:information_source: Already implemented via `list.count()`.
|
||||||
|
|
||||||
Counts the occurrences of a value in an list.
|
Counts the occurrences of a value in a list.
|
||||||
|
|
||||||
Uses the list comprehension to increment a counter each time you encounter the specific value inside the list.
|
Uses the list comprehension to increment a counter each time you encounter the specific value inside the list.
|
||||||
|
|
||||||
|
|||||||
@ -7,12 +7,9 @@ Use a regular expression to count the number of vowels `(A, E, I, O, U)` in a st
|
|||||||
```python
|
```python
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
def count_vowels(str):
|
def count_vowels(str):
|
||||||
return len(re.findall(r'[aeiou]', str, re.IGNORECASE))
|
return len(re.findall(r'[aeiou]', str, re.IGNORECASE))
|
||||||
```
|
|
||||||
|
|
||||||
``` python
|
|
||||||
count_vowels('foobar') # 3
|
count_vowels('foobar') # 3
|
||||||
count_vowels('gym')# 0
|
count_vowels('gym')# 0
|
||||||
```
|
```
|
||||||
|
|||||||
@ -11,6 +11,6 @@ def is_upper_case(string):
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
is_upper_case('ABC') # True
|
is_upper_case('ABC') # True
|
||||||
is_upper_case('a3@$') # True
|
is_upper_case('a3@$') # False
|
||||||
is_upper_case('aB4') # False
|
is_upper_case('aB4') # False
|
||||||
```
|
```
|
||||||
@ -2,14 +2,11 @@
|
|||||||
|
|
||||||
Function which accepts a dictionary of key value pairs and returns a new flat list of only the keys.
|
Function which accepts a dictionary of key value pairs and returns a new flat list of only the keys.
|
||||||
|
|
||||||
Uses the .items() function with a for loop on the dictionary to track both the key and value and returns a new list by appending the keys to it. Best used on 1 level-deep key:value pair dictionaries (a flat dictionary) and not nested data-structures which are also commonly used with dictionaries. (a flat dictionary resembles a json and a flat list an array for javascript people).
|
Uses the .keys() method of "dict" objects. dict.keys() returns a view object that displays a list of all the keys. Then, list(dict.keys()) returns a list that stores all the keys of a dict.
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
def keys_only(flat_dict):
|
def keys_only(flat_dict):
|
||||||
lst = []
|
return list(flat_dict.keys())
|
||||||
for k, v in flat_dict.items():
|
|
||||||
lst.append(k)
|
|
||||||
return lst
|
|
||||||
```
|
```
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
|
|||||||
@ -12,7 +12,7 @@ def zip(*args, fillvalue=None):
|
|||||||
result = []
|
result = []
|
||||||
for i in range(max_length):
|
for i in range(max_length):
|
||||||
result.append([
|
result.append([
|
||||||
args[k][i] if i < len(args[k]) else None for k in range(len(args))
|
args[k][i] if i < len(args[k]) else fillvalue for k in range(len(args))
|
||||||
])
|
])
|
||||||
return result
|
return result
|
||||||
```
|
```
|
||||||
|
|||||||
@ -1,5 +1,2 @@
|
|||||||
def keys_only(flat_dict):
|
def keys_only(flat_dict):
|
||||||
lst = []
|
return list(flat_dict.keys())
|
||||||
for k, v in flat_dict.items():
|
|
||||||
lst.append(k)
|
|
||||||
return lst
|
|
||||||
Reference in New Issue
Block a user