0

This seems to be a good way to get the transpose of a matrix. But I'm not sure what exactly is happening when the * operator is invoked. Can someone unpack that?

 >>> zip(*[[1,2,3], [4,5,6]])
 [(1,4), (2,5), (3,6)]
Keenan
  • 194
  • 1
  • 8

1 Answers1

2

The * operator is used to unpack the values, when using that in the list of lists like - zip(*[[1,2,3], [4,5,6]]) , it unpacks the outer list, and hence the actual input to zip function looks like - zip([1,2,3], [4,5,6]) . And when they get zipped you get the result - [(1,4), (2,5), (3,6)]

Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176