0
Please help with this.. using range.Generate the list 'A1' having numbers from 100 to 1 in decreasing order, which are also mult
Please help with this.. using range.Generate the list 'A1' having numbers from 100 to 1 in decreasing order, which are also multiple of 25. print 'A1'
3 Réponses
+ 3
A1 = {100, 75, 50, 25}
print(A1)
@Manorama is completely right, so there is nothing more to add
+ 1
Let me take a slightly different approach to Manorama:
A1 = reversed(filter(lambda x: not x % 25, (_ for _ in range(1,101) ) ) )
The result obtained is an iterator which is more memory-efficient if you mind the difference.
However, you can't get the items in A1 like what you did with list. You can get it through for loop or next function:
for item in A1:
print(item)
or
next(A1)
Second argument in filter function is a generator comprehension, which is more memory-efficient.