Answer the question
In order to leave comments, you need to log in
Why does the program skip an element in an iteration?
Why is [10, 20] skipped in iteration ?
def sum_of_intervals(intervals):
length = 0
while intervals:
inter = intervals.pop()
print(inter)
print('outer')
for x in intervals:
print(x)
if (min(x) <= sum(set(inter)) <= max(x)) or (min(inter) <= sum(x) <= max(inter)):
inter = inter + x
intervals.remove(x)
print(intervals)
print(inter)
print('inner')
length = length + (max(inter) - min(inter))
return intervals, length
print(sum_of_intervals())
Answer the question
In order to leave comments, you need to log in
Because you can't modify the sequence you're iterating over for-loop
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question