1

I want to get the elements of the array SIZE from the A_TABLE, just like it shows in the top part below, but with an iterator, as I totally failed to do in the bottom part. New to Python about one hour ago, and I'll keep looking, but any suggestions appreciated.

SIZE   = ('too small', 'just right', 'too large')

A_TABLE = {}
A_TABLE['size'] = SIZE
print "size is " + A_TABLE['size'][0]
print "size is " + A_TABLE['size'][1]
print "size is " + A_TABLE['size'][2]

for x in A_TABLE['size'][x]:
    print "size is " + A_TABLE['size'][x]
2
  • 1
    Your print statements show that you are using python2. If you are "new to python," you should be learning python3, not python2. Python2 is rapidly approaching end of life. Commented Feb 19, 2018 at 3:06
  • % python --version Python 2.7.6.Thanks. I will sort that out directly. Commented Feb 19, 2018 at 3:11

1 Answer 1

1

You're looping in the wrong way, here's how you should do it:

SIZE = ('too small', 'just right', 'too large')

A_TABLE = {}
A_TABLE['size'] = SIZE

for x in A_TABLE['size']: # change here
    print "size is " + x  # and here
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect. Thanks. Waiting '7 minutes' to accept answer.

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.