Skip to content
Advertisement

How to remove text in a list at each index

I have a list similar to:

['42344 xxxxxx xxxx 12','31232 zzzzzz xxxxx 15','3111 yyyyyy aaaaaa 34']

I need to modify the list to remove the first numbers only and display the list so that after each comma there is a new line. The expected output would be:

xxxxxx xxxx 12
zzzzzz xxxxx 15
yyyyyy aaaaaa 34

I tried many codes but I’m lost now and don’t know how to arrive to my desired output.

Advertisement

Answer

One way would be the str.split on whitespace, then slice off the first element, and join back together.

data = ['42344 xxxxxx xxxx 12','31232 zzzzzz xxxxx 15','3111 yyyyyy aaaaaa 34']
for line in data:
    print(' '.join(line.split()[1:]))

Output

xxxxxx xxxx 12
zzzzzz xxxxx 15
yyyyyy aaaaaa 34
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement