update keys_only snippet discription, changed func param to flat_dict

This commit is contained in:
Rob-Rychs
2018-04-15 10:22:54 -07:00
parent aa31f4cc74
commit 9f0bd80219

View File

@ -2,12 +2,12 @@
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 and not nested data-structures.
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).
``` python
def keys_only(dict):
def keys_only(flat_dict):
lst = []
for k, v in dict.items():
for k, v in flat_dict.items():
lst.append(k)
return lst
```