0

I have a list of lists with tuples. I want to get the length of a tuple using:

item1=(4, 8, 16, 30)
list6=[[(4, 8, 16, 29)], [(4, 8, 16, 30)], [(4, 8, 16, 32)]]
print("list6.index((4, 8, 16, 29)):",list6.index([item1]))
print("len(list6[1]):"), len(list6[1])

Output:    
list6.index((4, 8, 16, 29)): 1
len(list6[1]):

There is no value for len(list6[1]). Can someone show me the correct syntax for this?

3
  • 1
    Cannot reproduce. The print statement correctly outputs "1". Commented Jun 16, 2015 at 8:03
  • Cannot reproduce either. Statement prints 1 Commented Jun 16, 2015 at 8:04
  • The odd thing is the program exits correctly: "Process finished with exit code 0" Commented Jun 16, 2015 at 8:05

1 Answer 1

2

The code works fine in Python 2. If you are using Python 3, there is an issue with last line, because print is a function. So, because of where you've put the close parenthesis, only the first part is actually passed to print. Try this instead

print("len(list6[1]):", len(list6[1]))
Sign up to request clarification or add additional context in comments.

1 Comment

Rather shocking on my part. I may be relying too much on the editor to pick up the syntax errors. I am using Python 3. Great, thank you.

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.