Getting the below error while iterating tuples. I am not sure what changes do I need to apply to iterate. Any help would be appreciated.
ValueError: too many values to unpack (expected 3)
Program:-
def convert_tuple_to_dict(self, tup):
dt = defaultdict(list)
temp_lst = []
for i in range(len(tup)):
if (len(tup[i]) == 2):
for a, b in tup:
dt[a].append(b)
if (len(tup[i]) == 3):
print(tup[i])
for (a, b, c) in tup[i]:
dt[a].append(b)
dt[a].append(c)
return dict(dt)
run = DataType()
print(run.convert_tuple_to_dict(
(('1328', '50434022', '53327'), (777, '5000435011607', '00720645'))))
Traceback details:-
Traceback (most recent call last):
File "foo/DataType.py", line 95, in <module>
print(run.convert_tuple_to_dict(
File "foo/DataType.py", line 86, in convert_tuple_to_dict
for (a, b, c) in tup[i]:
ValueError: too many values to unpack (expected 3)
('1328', '50434022', '53327')
Expected Output:
{'1328': ['50434022', '53327'], 777: ['5000435011607', '00720645']}
tupat each iteration of the loop, to inspect what's going on? - clubby789for x,y,z in list? @Tester - taurus05