python - Appending new data to existing associative array -
i've been working on python last few months , encountered problem. so, have dictionary contains keys , no values.
{'_id' : none, 'game' : none, 'viewers' : none ....}
and want add data in list. example,
[123456, 'starcraft 2', 300, ....]
as might guess, order of elements inside list corresponds order of keys inside dict. think using loop solution couldn't come one.
extra question: dict above dictionaries inside list. and, want add same dictionary same keys , new values every time new list of data.
[{'_id': 001, 'game':'starcraft 2', 'viewers':300, ...}, {'_id': 002, 'game':'tetiris', 'viewers': 30, ...}, ... ]
how do that?
thanks, python friends!!
actually cannot dict because order not conserved. can use class ordereddict
shown here: python dictionary, how keep keys/values in same order declared?
what have list keys keep track of order:
my_keys = ['_id', 'game', 'viewers'] index, elt in enumerate(my_data): my_dict[my_keys[index]] = elt
Comments
Post a Comment