Python: how to find common values in three lists

前端 未结 3 485
情歌与酒
情歌与酒 2020-12-29 07:42

I try to find common list of values for three different lists:

a = [1,2,3,4]
b = [2,3,4,5]
c = [3,4,5,6]

of course naturally I try to use t

3条回答
  •  执笔经年
    2020-12-29 08:18

    out = [x for x in a if x in b and x in c]
    

    is a quick and simple solution. This constructs a list out with entries from a, if those entries are in b and c.

    For larger lists, you want to look at the answer provided by @poke

提交回复
热议问题