I wanted to convert the integer of tuple into string of tuple. For example:
data = [(2,3,4,...),(23,42,54,...),......]
would result in:
d = [('2','3','4',...),('23','42','54',....)......]
Please notice how tuple is big and list is also big.
I tried the code below but it doesn't give me the result I was looking for:
data = [(2,3,4,...),(23,42,54,...),......]
d=[]
for t in data:
d.append(str(t))
This gets close:
data = [[str(x) for x in tup] for tup in data]
If you actually need tuples:
data = [tuple(str(x) for x in tup) for tup in data]
Or, if you prefer a more "functional" approach:
data = [tuple(map(str, tup)) for tup in data]
Though it seems that map
has fallen out of favor with the python crowd (or maybe it never was actually in favor ;-).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With