Z
Z
Zorgios2021-08-12 14:36:16
Python
Zorgios, 2021-08-12 14:36:16

How to turn a list of strings into a list of tuples?

There is a list of strings of the form: How to turn it into a tuple of the form the standard application will split the string of the list character by character
a = ['abc', 'def']
b = [('abc',), ('def',)]

tuple

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cython, 2021-08-12
@Zorgios

b = [(el,) for el in a]
When you apply a tuple to a string, you don't stuff it into a tuple, you turn it into a tuple.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question