list1
您可以像这样制作一组名字
>>> {x.split()[0] for x in list1}
set(['john', 'jennifer', 'elizabeth', 'steven'])
您可以像这样进行各种设置操作
>>> list2 = ['john','jennifer']
>>> set(list2).difference(x.split()[0] for x in list1)
set([]) # ie False
>>> list3 = ['jack','jennifer']
>>> set(list3).difference(x.split()[0] for x in list1)
set(['jack']) # ie True
如果你真的需要布尔...
>>> bool(set(list2).difference(x.split()[0] for x in list1))
False
>>> bool(set(list3).difference(x.split()[0] for x in list1))
True
或相反...
>>> bool(not set(list2).difference(x.split()[0] for x in list1))
True
>>> bool(not set(list3).difference(x.split()[0] for x in list1))
False
对于新的 list4 测试用例
>>> list4 = ['john mayer', 'jennifer']
>>> {x.split()[0] for x in list1}.union(list1) > set(list2)
True
>>> {x.split()[0] for x in list1}.union(list1) > set(list3)
False
>>> {x.split()[0] for x in list2}.union(list2) > set(list3)
False
>>> {x.split()[0] for x in list1}.union(list1) > set(list4)
True