list =list(range(0, 20))
a = []
for i in w:
if i >= 7*0 and i < 7*1:
a.append(0)
elif i >= 7*1 and i < 7*2:
a.append(1)
.
.
.
.
elif i >= 7*n and i < 7*(n+1):
a.append(n)
else:
a.append(n+1)
If n is small in the for statement above, you can manually enter elif one by one.
As the length of the list gets longer, it is difficult to enter manually if n increases
I wonder what to do with a simple for statement.
Thank you for your reply.
python
a.append(min(i//7, n+1))
© 2024 OneMinuteCode. All rights reserved.