+ 3
What does this code actually do? a=[2*i for i in range(10**100)]
I understand it doesnt work with list comprehension due to MemoryError and it works with some concept called generators, which is in the next module, as per the note given on this slide. But what exactly does this code mean?
8 odpowiedzi
+ 2
Ohh cool
+ 1
The list starts with 0, 2, 4, 6, 8, 10,... You can try it yourself lowering the upper bound of range, like range(10)
+ 1
and 10**100 is 10 raised to the power 100?
+ 1
Yes, 10**100 is 10 raised to the power of 100. As you can imagine, it's a pretty big number.
+ 1
yeah
0
It creates a list consisting of doubled (2*i) for each i from 0 to 10**100 - 1. The list just happens to be too long to fit in memory. Generator won't return whole list at once, but rather 1 value at a time when asked, thus it's a viable workaround.
0
Okay so can you tell like few numbers of this particular list like four or five numbers
0
nice