Can someone please explain what is ' * ' doing in this code? or give me link where i can find more information regarding this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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', '')])

6th Sep 2020, 4:10 PM
partha
partha - avatar
1 Answer
+ 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!'
6th Sep 2020, 6:18 PM
Lothar
Lothar - avatar