By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,509 Members | 752 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,509 IT Pros & Developers. It's quick & easy.

'int' object not iterable

P: 1
Expand|Select|Wrap|Line Numbers
  1. def string_count(y):
  2.     count = 0
  3.     for a in y:
  4.      if(a=="ram"):
  5.        count=count+1
  6.        print count
  7.     else:
  8.       print "zero"
  9.  
  10.     x = ["sizz" ,"vixx", "dfd" ,"ram","furram","ram"]
  11.  
  12. string_count(x)
  13.  
Jun 20 '14 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 626
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.
Jun 20 '14 #2

P: 10
Just move definition of x before calling string_count function.
Jun 20 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.