+ 2
Please help me with the logic
list1 = [] list2 = [] for i in range(5)[::-1]: list1.append(i) for j in list1[::-2]: list2.append(j+1) print(list1[2])
5 Antworten
+ 9
Hi AMAN TOMAR
Posting numerous times in a row is borderline spam.
A better way to ask specific people for help (as you seem to have done) would be to create a new code that contains the problem and tag the people in the comments section.
+ 4
jay was not aware about it .just wanted some help.thnks
+ 4
KrOW thank you 😊
+ 2
+ 2
AMAN TOMAR in first loop range(5) return an range object. You can view this like a tuple (0,1,2,3,4). At this "tuple", you apply the slice operator [::-1] that in practice reverse the tuple then its (4,3,2,1,0). After this, list1 will be a list like [4,3,2,1,0].
In second loop, j will iterate on a new array created by slice operator of list1 that reverse it [0,1,2,3,4] and get like items every 2 items of this reversed array starting from first then j will iterate on [0,2,4].
You build list2 by adding one at every j then list2 will be [1,3,5] and at end third list2 item is printed (5)
P.S. Like jay said, if you tag specific users use code comments