0

Sorry this might be a very stupid question. But I did have bug with the following naming.

for i in my_hash_dict: #1st
 for y in my_hash_dict[i]:
 do something with i ...
for i in my_hash_dict: #2nd
 do something with i...

the problem is seems like if I reusing i this name in 2nd for loop , it "seems" will cost my program not running correctly. If I change the i in 2nd for loop, then seems everything working fine...

Maybe it just some of my stupid typo or something else cause this problem.

But I hope experiecned python programmer can give me some answers... Thankyou

asked Oct 23, 2012 at 7:36
2
  • 4
    You are missing a : at the end of the for line. Please post some real Python code. Commented Oct 23, 2012 at 7:37
  • sorry, im really a super big noob to python... fixed Commented Oct 23, 2012 at 7:42

2 Answers 2

7

The problem is that you are using the 'i' element as index.
Probably this code will work for you:

for element in my_hash_dict: 
 for y in element:
 do something with y ...
Toon Krijthe
53.6k38 gold badges151 silver badges204 bronze badges
answered Oct 23, 2012 at 7:53
Sign up to request clarification or add additional context in comments.

Comments

1

Its a syntax issue as Tichodroma mentioned, take a look at this documentation, your example looks fine you just need to add the : if you still get an unexpected output please post it.

answered Oct 23, 2012 at 7:43

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.