Python Count the number of substring in list from other string list without duplicates

后端 未结 6 1128
小鲜肉
小鲜肉 2021-01-13 01:03

I have two list:

main_list = [\'Smith\', \'Smith\', \'Roger\', \'Roger-Smith\', \'42\']
master_list = [\'Smith\', \'Roger\']

I want to coun

6条回答
  •  伪装坚强ぢ
    2021-01-13 01:38

    What about this

    main_list = ['Smith', 'Smith', 'Roger', 'Roger-Smith', '42']
    master_list = ['Smith', 'Roger']
    
    print len([word for word in main_list if any(mw in word for mw in master_list)])
    

提交回复
热议问题