1

I get "TypeError: iterable argument required" when i try to execute the code below:

for i in range(len(SE_FE_Lists)):                    
    print "** ", SE_FE_Lists[i]["List_contents"]
    if ":" in SE_FE_Lists[i]["List_contents"]:
        print ": ", SE_FE_Lists[i]
        print "*--* ", SE_FE_Lists[i]["List_contents"]
    if " " in SE_FE_Lists[i]["List_contents"]:
        print "Space :", SE_FE_Lists[i]
        print "*--* ", SE_FE_Lists[i]["List_contents"]    

The error is located in the line if ":" in List[i]["List_contents"]:

The contents of the list :

[{'List_selection': 'List1', 'List_contents': '1:4'}, {'List_selection': 'List2', 'List_contents': '1 2 4'}, {'List_selection': 'List3',
 'List_contents': 1}]

As output i get :

**  1:4

:  {'List_selection': 'List1', 'List_contents': '1:4'}

*--*  1:4

**  1 2 4

Space : {'List_selection': 'List2', 'List_contents': '1 2 4'}

*--*  1 2 4

**  1

Thanks.

1
  • 1
    What are the contents of List? Commented Aug 21, 2012 at 8:52

2 Answers 2

2

First, if you want to iterate over items of your object List, you should use the pythonic way of doing it :

for item in List:

    if ":" in item["List_contents"]:
        print "*--* ", item["List_contents"]
    if " " in item["List_contents"]:
        print "*--* ", item["List_contents"]  

for the error you encounter, it looks like your List object is not a dictionnary list.

EDIT :

after your edition, the problem is due to the last item of your List : {'List_selection': 'List3', 'List_contents': 1}, here the member 'List_contents' is an integer, and python can't find ":" in an integer... If you can't modify the content of the list, try to force python to use a string with the str() method :

if ":" in str(item["List_contents"]):
Sign up to request clarification or add additional context in comments.

Comments

1

The problem is there is an integer in your dictionary, not an iterable:

{'List_selection': 'List3', 'List_contents': 1}

This line:

if ":" in SE_FE_Lists[i]["List_contents"]:

is looking for ": " in the integer 1. the in operator requires an iterable, not an integer, so that's apparently the error. If the list contents looked like this it should work:

{'List_selection': 'List3', 'List_contents': '4 5 6'}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.