Hi I have two lists list1 and list2 I want to extract all values that exist in list1 and don’t exist in list2. I tried this code: Read more
You can use Counter if you want to do multiple count of the list from collections import Counter list = ['Jones','Adams','Frank','John','Lopez','Jones','Smith','Ivan','Julian','Carlos','Adams','Frank','Jones','John','Ivan'] print(Counter(list)) Result: Counter({'Jones': 3, 'Adams': 2, 'Frank': 2, 'JRead more
You can use Counter if you want to do multiple count of the list
[crayon-6855aae0cd218098207076/]
Result:
[crayon-6855aae0cd21c969897126/]
You can simly use a for loop with append to list. list1 = ['lion', 'dog', 'cat', 'tiger', 'cat', 'cat', 'zebra'] list2 = ['monkey', 'tiger', 'cow', 'mouse'] my_list = [] for animal in list1: #iterating over list1 if animal not in list2 and animal not in my_list: my_list.append(animal) #add item to tRead more
You can simly use a for loop with append to list.
[crayon-6855aae0cd414670960752/]
[crayon-6855aae0cd417049066618/]
kind regards
See less