Is there a way to cast argument list into list?
Somthing like:
list(*arguments)
Dosen’t work because list() take at most 1 argument…
im trying to cast tuple of tuples into a list
list(('a', *('b', 5))
dosent work at all…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For a tuple of tuples, eg,
Getting it into a list depends on what list you are expecting – you can pass the tuple straight into
list(it takes any iterable) to get a list of tuples:If instead you want a flattened list, you want
itertools.chain– it gives you a generator, but you can pass that intolistto get a list:If you want a list of lists, you want a list comprehension:
To flatten a heterogenous tuple of tuples and single values, it gets a little more complicated – what you want to do is turn all the single values into single-length tuples or lists, and then it’s the same as the
chainexample above. If you only want to flatten the tuples, and not, eg, nested lists, you could do this: