Skip to content
Advertisement

how do i compare 2 different string lists and return the difference if one is bigger?

please help me subtract the existing string from the list VideoList so we have a difference and should be formatted into a new list

Database = ["vill du ha","garry", "yao"]  #this is the list of the local data we have 
VideoList = ["garry", "vill du ha", "yao", "potato"] #this list has the same data as Database or more

#My code:
if len(VideoList) == len(Database):
    print("No new videos")
else:
 new_List = #i don't know what to do here but i want the list VideoLise to subtract the existing string in Data base and return what's left from VideoList as a List so the output should be NewList = ["potato"]

Advertisement

Answer

You can check whether the element of VideoList is present in Database or not like

Database = ["vill du ha","garry", "yao"]
VideoList = ["garry", "vill du ha", "yao", "potato"] 

if len(VideoList) == len(Database):
    print("No new videos")
else:
    new_list=[]
    for element in VideoList:
        if not element in Database:
            new_list.append(element)
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement