Home > Net >  How to remove double quotes to make tuple in python from the array
How to remove double quotes to make tuple in python from the array

Time:05-05

Input is

["('ABCD','ABCD.pdf',10)", "('ABCD','ABCD.pdf',14)", "('ABCD','ABCD.pdf',15)"]

Expected output

[('ABCD','ABCD.pdf',10),('ABCD','ABCD.pdf',14), ('ABCD','ABCD.pdf',15)]

CodePudding user response:

One quick solution is to use eval and map. Example:

text = ["('ABCD','ABCD.pdf',10)", "('ABCD','ABCD.pdf',14)", "('ABCD','ABCD.pdf',15)"]
out = list(map(eval, text))

Out contains the desired result.

See the python docs here

  • Related