I have a list
list = ['MANAGEMENT (1) (Distributor)',False,'Worker(1) (Distributor)',]
I need to remove the boolean and change it to a string
list = ['MANAGEMENT (1) (Distributor)','False','Worker(1) (Distributor)',]
I have tied to use (str) but this does not work. I have a feeling I need to use list comprehension but I am not sure how to set that up.
Mureinik
316k54 gold badges404 silver badges406 bronze badges
asked Jan 22, 2021 at 23:07
apexprogramming
4334 silver badges17 bronze badges
1 Answer 1
A list comprehension would definitely be a way to solve this, by applying str to all the items in it:
lst = [str(i) for i in lst]
answered Jan 22, 2021 at 23:09
Mureinik
316k54 gold badges404 silver badges406 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
listas a variable name, since it is a reserved wordstr"does not work"? It works fine for me. You didn't post your failing attempt, so we can't diagnose that for you.