I was wondering if you guys might be able to give me some advice in regards to making the performance of my code much better.
I have a set of for loops which look to see if a key is in a dictionary of which its values are a list, if the key exists, it appends to the list and if it doesnt it adds a new list in for that key
dict={}
for value in value_list:
if value.key in dict.keys():
temp_list = dict[value.key]
temp_list.append(value.val)
dict[value.key] = temp_list
else:
dict[value.key] = [value.val]
Now this code works fine, but evenrually as the dictionary starts to fill up the line value.key in dict.keys() becomes more and more cumbersome.
Is there a better way of doing this?
Thanks,
Mike
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…