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

creating an f-string generator expression and with index values

I don’t have enough experience with generator expression to figure this out.
I have a list and input statement like so:

work = ['Read', 'Write', 'Program', 'Email']
assign = input(f"Select what you have worked on > {(str(x) for x in work)}")

The above code is not working! The work list might change. I also want to see a different input message that is more like.

Select what you have worked on > 0: Read, 1: Write, 2: Program, 3: Email >

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

How do you recommend getting this input question?

>Solution :

Use str.join():

>>> work = ['Read', 'Write', 'Program', 'Email']
>>> f"Select what you have worked on > {', '.join(f'{i}: {x}' for i, x in enumerate(work))}"
'Select what you have worked on > 0: Read, 1: Write, 2: Program, 3: Email'
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