如何使用python group by检索不区分大小写的单词?

时间:2016-11-22 10:59:07

标签: python

things=[("red",1),("red",2),("green",5),("green",10),("red",15)]
for key,value in groupby(things,lambda x:x[0]):
    for thi in value:
        if(b==key):
            print("things present in:",thi[1])

1 个答案:

答案 0 :(得分:1)

只需将casefold添加到字符串中即可。

things=[("red",1),("red",2),("green",5),("green",10),("red",15)]
for key,value in groupby(things,lambda x:x[0]):
    for thi in value:
        if b.casefold() == key.casefold():
            print("things present in: ", thi[1])