Last active
May 29, 2020 07:00
-
-
Save mjtiempo/85f15220c11f6431ef3b3f7cbe1ab572 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
users = jsonf_to_list('en_users.json') | |
uid_map = map(lambda user: user['id'], users) | |
user_list = list(uid_map) | |
user_ids = list(filter(None, user_list)) | |
def search_dict_list(dict_list, dict_id): | |
return next((item for item in dict_list if item["id"] == dict_id), None) | |
def jsonf_to_list(filename): | |
with open(filename, 'r') as f: | |
thelist = json.load(f) | |
return thelist | |
def list_to_jsonf(filename, thelist): | |
with open(filename, 'w') as w: | |
json.dump(thelist, w, indent=4) | |
''' flatten list of list''' | |
flat_list = [item for sublist in main_list for item in sublist] | |
''' alternative way to flatten list of list (not tested)''' | |
from itertools import chain | |
flat_list = list(chain.from_iterable(main_list)) | |
''' search list of dictionary using key and value ''' | |
def dictionary_search(dict_list, key, value): | |
return next((item for item in dict_list if item[key] == value), None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment