+ 1
Can someone please explain what is ' * ' doing in this code? or give me link where i can find more information regarding this?
a,b = zip(*[('g', 'd'), ('r', 'a'), ('e', 'y'), ('a', '!'), ('t', '')])
1 Respuesta
+ 4
As already explained, '*' is used here as unpack operator. We have a list of tuples, so the unpack operator extracts these tuples, and zip() (zip allows to iterate over n iterables in parallel) is used to put them together to finally 2 tuples, that contain the elements:
a is: ('g', 'r', 'e', 'a', 't') -> join them to: 'great'
b is: ('d', 'a', 'y', '!', '') -> join them to: 'day!'