-1

I read a file that has 7 values with 7 different keys on each line and I put them in a dictionary. Some of the keys have '*' values and when I iterate through them I want to skip those in my operation. So, if my dictionary name is mydictionary can I do this:

    for entry in mydictionary:
        if entry != '*'
           do some work here
HassanB
  • 51
  • 1
  • 5

1 Answers1

1

Currently your for loop with only grab the key and not the values.

You need to do something like this to get both the key and value.

for key, value in mydictionary.iteritems():
    if value != '*':
        # Do something

Something similar to this has been asked before. You can read about it here.

Community
  • 1
  • 1
JakeGreen
  • 89
  • 5