Question: Question: You're working with a dataset on capital cities around the world. This dataset includes a field that containsinformation on both city and country. You'd
Question: You're working with a dataset on capital cities around the world. This dataset includes a field that containsinformation on both city and country. You'd like to separate this field into two fields, a city field and a countryfield. In the current field, city and country are separated by either a comma or a period. Complete the functionparsecitycountry to
You're working with a dataset on capital cities around the world. This dataset includes a field that contains
information on both city and country. You'd like to separate this field into two fields, a city field and a country
field. In the current field, city and country are separated by either a comma or a period. Complete the function
parse
city
country to split city and country into two strings and return only the city.
def parse
city
country
text
:
pattern
#enter the regex pattern here
result
re
pattern
text
#enter the re method here
if len
result
:
return
return #return the correct capturing group
print
parse
city
country
Paris
France
# should return Paris
print
parse
city
country
Mumbai
India
# should return Mumbai
print
parse
city
country
Rio de Janeiro. Brazil"
# should return Rio de Janeiro
print
parse
city
country
Tokyo
Japan
# result should be blank
Run
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
