Answers for "python:find the first reoeted word in given string"

4

select first word in string python

name = "Rick Sanchez"
first_name = name.split(' ').pop(0)
print(first_name)
#Output
'Rick'

#BONUS
#From strings in a list (using list comprehension)
names = ["Rick Sanchez", "Morty Smith", "Summer Smith", "Jerry Smith", "Beth Smith"]
first_names = [name.split(' ').pop(0) for name in names]
print(first_names)
#Output
['Rick', 'Morty', 'Summer', 'Jerry', 'Beth']
Posted by: Guest on August-21-2021

Code answers related to "python:find the first reoeted word in given string"

Python Answers by Framework

Browse Popular Code Answers by Language