If condition giving worng result opposite result to its condition

Question:

If the condition gives worng result opposite result to its condition. here I want to print the links that do not start with youtube.com or include youtube.com but its prints the 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%20speculate%20that%20friendship%20bloomed,Those%20Who%20Must%20Be%20Obeyed.",
"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")
Asked By: Info Rewind

||

Answers:

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)
Answered By: quamrana
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.