Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate over a dict except for x item items

I have a dict in this format:

d_data = {'key_1':value_1,'key_2':value_2,'key_3':value_3,'key_x':value_x,'key_n':value_n}

and I have to iterate over it's items:

for key,value in columns.items():
    do something

except for the pair:

'key_x':value_x
like image 691
Luis Ramon Ramirez Rodriguez Avatar asked Mar 23 '16 17:03

Luis Ramon Ramirez Rodriguez


1 Answers

Simply use the continue statement, to skip ahead to the next iteration of the for loop:

for key,value in columns.items():
    if key == 'key_x':
        continue
    # do something
like image 67
wim Avatar answered Sep 17 '22 18:09

wim