Using split function to split words where an empty space is found

Publicado em: 12 Junho 2017
no canal de: Online Skills
102
0

I have started by creating a list called namelist consisting of three names. First and last names are separated by space
namelist=["Emma Wild", "Liam Wilson", "Elijah Mason"]
To find the first names, I will find the space choose the first part [0] of the split and put the names into new list called firstnames.
firstnames = [name.split(' ')[0] for name in namelist]
firstnames
OUTPUT:
['Emma', 'Liam', 'Elijah']
To create lastnames list, use the same format, only selecting the part after the space [1]
lastnames = [name.split(' ') [1] for name in namelist]
lastnames
OUTPUT:
['Wild', 'Wilson', 'Mason']


Nesta página do site você pode assistir ao vídeo on-line Using split function to split words where an empty space is found duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Online Skills 12 Junho 2017, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 102 vezes e gostou 0 espectadores. Boa visualização!