0
How to convert a tuple into strings (using map, filter etc)
5 Respuestas
+ 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))
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.
0
For example ('s', 'a', 'm', 1,2,3) returns 'sam123'
0
Is there any other way where I don't use the .join cuz i didn't learn it
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/