Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove quotes from a list of tuples in python

Hoping someone can help me to figure out how to exclude quotes from a list of tuples and display it in the final output. I’ve tried regex a nd f-string format but nothing seem to work 🙁

lts = [('A', 1), ('B', 14), ('C', 12), ('D', 11), ('E', 9)]
Regex - [(re.sub(r"[^a-zA-Z0-9 ]", "", l[0]), l[1]) for actor in lst]
F-string - f'{l[0]}, {l[1]}' for l in lst]

desired_output = [(A, 1), (B, 14), (C, 12), (D, 11), (E, 9)] 

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Code:

lts = [('A', 1), ('B', 14), ('C', 12), ('D', 11), ('E', 9)]
a = "["
b = []
for l in lts:
    b.append( f"({l[0]},{l[1]})" )
e = ", ".join(b)
print(e)
for each in e:
    a += each
a += f"]"
print(a)

Output

(A,1), (B,14), (C,12), (D,11), (E,9)
[(A,1), (B,14), (C,12), (D,11), (E,9)]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading