0

How to convert a tuple into strings (using map, filter etc)

13th Mar 2020, 6:20 AM
Tan
5 odpowiedzi
+ 1
`map` works, but not `filter`. `filter` serves a different purpose. tup = ('S', 'o', 'l', 'o', 'L', 'e', 'a', 'r', 'n', ' ', 2, 0, 2, 0) print(tup, type(tup)) result = ''.join(tuple(map(str, tup))) print(result, type(result))
13th Mar 2020, 7:35 AM
Ipang
0
Elaborate some more, I'm not understanding your intention. Why you need to convert a tuple to a string? `print` function can display tuples just fine without having to convert them to string.
13th Mar 2020, 6:40 AM
Ipang
0
For example ('s', 'a', 'm', 1,2,3) returns 'sam123'
13th Mar 2020, 6:42 AM
Tan
0
Is there any other way where I don't use the .join cuz i didn't learn it
13th Mar 2020, 11:46 AM
Tan
0
You can use for loop and accumulate each tuple element, but you'd still have to convert the numeric elements into string. (Edit) You can find `join` example in this chapter https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2456/
13th Mar 2020, 12:12 PM
Ipang