My python code if conditon giving me worng result opposite result to its condition. here I want to print the links that not start with youtube.com or include youtube.com but its printing full list
fetchurl = ["https://www.smithsonianmag.com/science-nature/how-wolves-really-became-dogs-180970014/",
"https://www.youtube.com/watch?v=DdPMV7GO8q0",
"https://www.npr.org/2013/01/25/170267847/canine-mystery-how-dogs-became-mans-best-friend",
"https://www.youtube.com/watch?v=DdPMV7GO8q0",
"https://www.youtube.com/watch?v=nDt0HKSdRRw&t=554",
"https://www.youtube.com/watch?v=nDt0HKSdRRw&t=554",
"https://www.youtube.com/watch?v=DdPMV7GO8q0",
"https://www.bbc.com/news/science-environment-40638584",
"https://www.youtube.com/watch?v=nDt0HKSdRRw&t=79",
"https://www.bbc.com/news/science-environment-40638584",
"https://www.newscientist.com/article/2264329-humans-may-have-domesticated-dogs-by-accident-by-sharing-excess-meat/",
"https://www.mypet.com/basic-pet-care/dog-mans-best-friend.aspx#:~:text=Scientists speculate that friendship bloomed,Those Who Must Be Obeyed.",
"https://www.youtube.com/watch?v=tggdERc8E6Y&t=11",
"https://www.npr.org/2013/01/25/170267847/canine-mystery-how-dogs-became-mans-best-friend"]
for i in range(len(fetchurl)):
url = random.choice(fetchurl)
if url != fetchurl[i].startswith("https://www.youtube.com/"):
print(url)
else:
print("lol")
CodePudding user response:
If you want to print all "links that not start with youtube.com or include youtube.com "
for url in fetchurl:
if "https://www.youtube.com/" not in url:
print(url)
The above may not exclude everything. If so try this:
for url in fetchurl:
if "youtube.com" not in url:
print(url)