jeudi 6 mai 2021

Python print based on the URLS [duplicate]

I have the following urls:

URLS = ['www.google.com/acv/',
'www.google.com/qwe/',
'www.yahoo.com/ddd/,
'www.yahoo.com/asd']

I would like to print if the URL begins with www.google.com then google or if it is from www.yahoo.com then yahoo. What I tried so far?

op =[]
for i in URLS:
  if i == 'www.google.com':
     print('Google!')
  if i == 'www.yahoo.com':
     print('Yahoo!)

This does not work well. How do I do that?

Aucun commentaire:

Enregistrer un commentaire