'int' object not iterable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rishanth
    New Member
    • Jun 2014
    • 1

    'int' object not iterable

    Code:
    def string_count(y):
        count = 0
        for a in y:
         if(a=="ram"):
           count=count+1
           print count
        else:
          print "zero"
    
        x = ["sizz" ,"vixx", "dfd" ,"ram","furram","ram"]
    
    string_count(x)
    Last edited by bvdet; Jun 20 '14, 03:39 PM. Reason: Fix code tags
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    You should get an error on the
    string_count(x)
    line saying that x is not defined because x is inside the function in the code you posted and therefore local to the function only. There is no error "'int' object not iterable" and you have not posted the complete error message so we have no way of knowing what the problem is.

    Comment

    • invention
      New Member
      • Jun 2014
      • 10

      #3
      Just move definition of x before calling string_count function.

      Comment

      Working...