0

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
2
  • 2
    I would avoid using list as a variable name, since it is a reserved word Commented Jan 22, 2021 at 23:10
  • 1
    How is it that str "does not work"? It works fine for me. You didn't post your failing attempt, so we can't diagnose that for you. Commented Jan 22, 2021 at 23:26

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.