python - Find the element "left" in a list -
i have list list1 = ["hello", "goodbye", "ohai"]
.
i have list, list2 = ["hello", "goodbye"]
.
i want remaining items in list1
, in case "ohai"
.
>>> list1 = ["hello", "goodbye", "ohai"] >>> list2 = ["hello", "goodbye"] >>> set(list1) ^ set(list2) set(['ohai'])
if supposed use lists only, can iterate:
>>> [item item in list1 if item not in list2] ['ohai']
but why when have sets ;-)
Comments
Post a Comment