简体   繁体   中英

Query about range & lists python

I have a list of values and I want to create a for loop such that in each iteration the range function gets a different start value from list, whereas the end value is same. I use len function but it is not what I need. How should I do it?

list_values = [0, 100, 200, 300, 400, 500]

for x in range(len(list_values), 600):
    print(x)

I want the start value of loop to be changed as 0, 100, 200, 300 etc. in each iteration of loop eg

for x in range(0,600)
for x in range(100,600)
for x in range(200,600) etc.

You need an outer loop to iterate on list_values then the inner loop have the range

list_values = [0, 100, 200, 300, 400, 500]
end_value = 600
for start_value in list_values:
    for x in range(start_value, end_value):
        pass

Is this what you want? The loop counts from 0 to 600, then it restarts and counts from 100 to 600, and so forth...

list_values = [0, 100,200,300,400,500]

for item in list_values:
    for x in range(item, 600):
        print(x)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM