+ 1

Convert all element of list to string

for example list=[a,b,c] to list=['a','b','c'] a,b and c is not defined

29th Nov 2017, 1:34 AM
LLuthfiY
LLuthfiY - avatar
3 Answers
+ 5
Slightly different answer using map () https://code.sololearn.com/cPpssx11uUyK/?ref=app
2nd Dec 2017, 12:40 AM
Eric Blinkidu
Eric Blinkidu - avatar
+ 4
Actually, "list" can't be the name of a list, but if you must use that name... list = [str(x) for x in list] should work, assuming a, b and c are variables.
29th Nov 2017, 2:09 AM
blackcat1111
blackcat1111 - avatar
+ 3
Okay, a better example will be [1,2,3] to ['1','2','3'] Use the map function. map(whatever function you want, whatever iterable you want) the function must be a lambda or an in-built function. For example, map(lambda x:x+1,thatlistabove) will create a map object that stores [2,3,4] and to get your list back, use list(). For your query, I suggest you use list(map(str,thatlistabove)). #remember to store it!
2nd Dec 2017, 3:38 AM
šŸ‘‘ Prometheus šŸ‡øšŸ‡¬
šŸ‘‘ Prometheus šŸ‡øšŸ‡¬ - avatar