Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

Let's say I have a list

p = [[1,2,3],[4,5,6]]

If I do:

>>>d=zip(p)

>>>list(d)

[([1, 2, 3],), ([4, 5, 6],)]

What I get:

>>>d=zip(*p)

>>>list(d)

[(1, 4), (2, 5), (3, 6)]

I have discovered that adding a '*' before the list name gives my necessary output, yet I can't have out the effect in their activity. Would you be able to please clarify the distinction?

1 Answer

0 votes
by (26.4k points)

The zip needs a lot of contentions to zip together, however what you have is a single argument (a list, whose components are likewise records). The * in a function call "unloads" a list (or other iterable), making every one of its components a different contention. So without  *, you're doing zip( [[1,2,3],[4,5,6]] ) and with *, you're doing zip([1,2,3], [4,5,6]).

Want to learn python to get expertise in the concepts of python? Join python certification course and get certified

Browse Categories

...