I have a large number of two-membered sub-lists that are members of a list called mylist:
mylist = [[\'AB001\', 22100],
[\'AB001\', 32
None in this case, if the key is nonexistent.None, so this method never raises a KeyError.
None is a value in the dictionary, then change the default value returned by .get.
test.get(t[0], 'something here')key, and then add the list, t, as the dict value.test = dict()
for t in mylist:
if test.get(t[0]) == None:
test[t[0]] = [t]
else:
test[t[0]].append(t)
final = list(test.values())
# print final results in
[[['AB001', 22100], ['AB001', 32935], ['AB001', 34439]],
[['XC013', 99834], ['XC013', 86701]],
[['VD126', 18884]]]