Merge branch 'master' into master

This commit is contained in:
Angelos Chalaris
2019-07-18 08:18:40 +03:00
committed by GitHub
9 changed files with 14 additions and 23 deletions

View File

@ -2,7 +2,7 @@
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
def byte_size(string):
@ -12,4 +12,4 @@ def byte_size(string):
```python
byte_size('😀') # 4
byte_size('Hello World') # 11
```
```

View File

@ -2,7 +2,7 @@
: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.

View File

@ -7,12 +7,9 @@ Use a regular expression to count the number of vowels `(A, E, I, O, U)` in a st
```python
import re
def count_vowels(str):
return len(re.findall(r'[aeiou]', str, re.IGNORECASE))
```
``` python
count_vowels('foobar') # 3
count_vowels('gym') # 0
count_vowels('foobar') # 3
count_vowels('gym')# 0
```

View File

@ -11,6 +11,6 @@ def is_upper_case(string):
```python
is_upper_case('ABC') # True
is_upper_case('a3@$') # True
is_upper_case('a3@$') # False
is_upper_case('aB4') # False
```
```

View File

@ -2,14 +2,11 @@
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
def keys_only(flat_dict):
lst = []
for k, v in flat_dict.items():
lst.append(k)
return lst
return list(flat_dict.keys())
```
``` python

View File

@ -12,7 +12,7 @@ def zip(*args, fillvalue=None):
result = []
for i in range(max_length):
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
```