如何在不使用Set的情况下查找元组中的Missing和其他值。
例如,
tuple1= ("apple", "banana", "cherry")
tuple2= ("apple", "banana", "mango")
缺失值:樱桃
附加值:芒果
答案 0 :(得分:1)
使用列表理解:
tuple1= ("apple", "banana", "cherry")
tuple2= ("apple", "banana", "mango")
# Missing:
print([x for x in tuple1 if x not in tuple2]) # ['cherry']
# Additional:
print([x for x in tuple2 if x not in tuple1]) # ['mango']