Stewie
Stewie

Reputation: 151

How to remove string's quotation marks which inside of a nested list

I have a code block as shown below:

lst=[67310,0,"May the force be with you"]
print(" ".join(repr(i) for i in lst).replace("'",""))

Output is:

67310 0 May the force be with you

But if I had a list, something like that:

lst=[[67310,0,"May the force be with you"],[65310,1,"I'm getting too old for this stuff"]]
for j in lst:
    print(" ".join(repr(i) for i in j).replace("'",""))

The output is:

67310 0 May the force be with you
65310 1 "Im getting too old for this stuff"

The problem is I want a output without quotation marks like that:

67310 0 May the force be with you
65310 1 I'm getting too old for this stuff

How can I solve this problem easily? Thanks for help

Upvotes: 4

Views: 492

Answers (2)

hygull
hygull

Reputation: 8740

Just try this, l think this is what you want.

lst=[[67310,0,"May the force be with you"],[65310,1,"I'm getting too old for this stuff"]]
for  j in lst:
    print(" ".join(str(i) for i in j).replace("'",""))

# 67310 0 May the force be with you
# 65310 1 Im getting too old for this stuff

Upvotes: 3

PurpJuice
PurpJuice

Reputation: 98

Try this instead:

for j in lst:
    print(" ".join(repr(i) for i in j).replace('"', ''))

In your .replace you were replacing the', not the ".

Upvotes: 0

Related Questions