Skip to content

Instantly share code, notes, and snippets.

@mjtiempo
Last active May 29, 2020 07:00
Show Gist options
  • Save mjtiempo/85f15220c11f6431ef3b3f7cbe1ab572 to your computer and use it in GitHub Desktop.
Save mjtiempo/85f15220c11f6431ef3b3f7cbe1ab572 to your computer and use it in GitHub Desktop.
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