0

When I create a tuple where its only component is another tuple, such as ((1, 2)), python automatically changes it to simply (1, 2).

This is a really simple problem that I hope will at least have some possible workaround.

4
  • Try using ((1,2),). Commented Sep 3, 2019 at 2:25
  • 1
    ((1,2)) is not a singleton tuple containing another tuple for the same reason (1) is not a singleton tuple containing an int, because the outer parentheses don't make a tuple, the comma creates the tuple. you need ((1,2),) or even (1,2), Commented Sep 3, 2019 at 2:26
  • @juanpa.arrivillaga I'm not convinced this is a duplicate, even if the answer is related. Commented Sep 3, 2019 at 2:35
  • @MarkRansom it's the closest one, it's a common question of how to create a tuple with a single item, whether that item is an empty tuple or a 2 tuple doesn't seem that significant of a difference to me. Commented Sep 3, 2019 at 2:35

1 Answer 1

0

Your syntax isn't what you think it is.

This will create your nested tuple.

((1,2),)

Without the extra comma, you are just grouping the expression (think (1+2)).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.