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

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -