Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Manipulating List
#3
Just for oneliner fun:

>>> names = 'Cohn, Mildred; Dolciani, Mary P.; Rees, Mina; Teitelbaum, Ruth; Yalow, Rosalyn'
>>> print(*[f'{item[1][0]}. {item[0]}' for item in [name.split(', ') for name in names.split('; ')]], sep='\n')
M. Cohn
M. Dolciani
M. Rees
R. Teitelbaum
R. Yalow
EDIT: to get expected output ('You entered:' followed by empty line):

>>> print('You entered:\n', *[f'{item[1][0]}. {item[0]}' for item in [name.split(', ') for name in names.split('; ')]], sep='\n')
You entered:

M. Cohn
M. Dolciani
M. Rees
R. Teitelbaum
R. Yalow
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Manipulating List - by frenchyinspace - Oct-08-2019, 06:07 AM
RE: Manipulating List - by buran - Oct-08-2019, 07:19 AM
RE: Manipulating List - by perfringo - Oct-08-2019, 07:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Manipulating panda dataframes more python-like badtwistoffate 4 2,121 Jan-31-2023, 04:30 AM
Last Post: deanhystad
  Manipulating code to draw a tree Py_thon 8 3,332 Nov-21-2019, 05:00 PM
Last Post: sumana
  Manipulating __init__ method schniefen 5 3,601 May-06-2019, 11:22 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020