Why is it printing a tuple instead of a list? | SoloLearn: Learn to code for FREE!

+2

Why is it printing a tuple instead of a list?

https://code.sololearn.com/cSssNts1dao3/?ref=app

5/18/2020 1:42:03 PM

Alen Antony

8 Answers

New Answer

+2

Because the fragments of your list are not displayed as a new list, but as fragments of the old. In general, c[9] you have just a fragment of the list, but to make it a new list, you need to use "list"

+2

a=range(10) b=range(10) c=list(zip(a,b)) print(list(c[9])) #i think, It will help you) #Initially, it was saved as a tuple. And if you want to make it a list, give it the "list" instruction at the output.

+2

That's just what zip does: Returning a tuple of the n-th elements of your iterables.

+1

Use [ ] brackets for list and ( ) For tuples

+1

Can you explain the function zip() and list(), why list() should be used twice?

+1

There is no need to use list twice in this code. It can be done like this: a = range(10) print(list(zip(a, a))[9]) # or like this: ( when 2 different ranges should be used like print(list(zip(range(0,10), range(3,13)))[9]) print(list(zip(range(10), range(10)))[9])

0

Thanks

0

Good luck)