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

How to create tuple of string list

I have one question .
I don’t create list or tuple of string list
Example I have list

[‘test1,test2,2020-10-12,None,None’,
"test5,test6,2021-11-24,None,None",
‘test7,test8,2021-11-24,None,None’]

I need tuple for example

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

[(‘test1,test2,2020-10-12,None,None’),
("test5,test6,2021-11-24,None,None"),
(‘test7,test8,2021-11-24,None,None’)]

Code for create first list is

list_t = (','.join((str(value) for key, value in l.items())) for l in r1)

>Solution :

From your desired output, it looks like you just want to wrap each item in the list in a tuple of length one. The following code accomplishes this:

items = ['test1,test2,2020-10-12,None,None', "test5,test6,2021-11-24,None,None", 'test7,test8,2021-11-24,None,None']
items_wrapped = [(i,) for i in items]

However, if you’d like to split the strings into the tuples you can do it like so:

items = ['test1,test2,2020-10-12,None,None', "test5,test6,2021-11-24,None,None", 'test7,test8,2021-11-24,None,None']
items_wrapped = [tuple(i.split(',')) for i in items]
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