I decided to start learning python from scratch using udemy, and my instructor gave an example which was too simple, so I wanted to make It more complex. However I did experience an error and I understand why I'm getting the error but don't know how to bypass it.
Here is the code in question:
mylist = [(1,2,3),(5,6,7),(8,9)]
for a,b,c in mylist:
print(b)
the output will be 2 6 and then an error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-10-a5ddba3739a9> in <module>
1 mylist = [(1,2,3),(5,6,7),(8,9)]
2
----> 3 for a,b,c in mylist:
4 print(b)
ValueError: not enough values to unpack (expected 3, got 2)
Because the tuple is not the same as the first two the error occurs.
How can i fix such an issue if something similar happens in the future, because in theory It could happen and not only i can add different sized tuples in a list but other types as well.
Thanks
Edit:
Extended Unpacking was the solution, thank you everyone for the help.