python-3.x - 为什么在以下代码中使用 set 命令有好处?
问题描述
在下面的代码中,没有重复,这意味着我看不出为什么要使用 set 命令。
代码:
def isPalindrome(word):
return word == word[::-1]
def getPalindromesFromStr(inputStr):
cleanStr = inputStr.replace(",","").lower()
words = set(cleanStr.split(" "))
wPalindromes = [word for word in words if isPalindrome(word) and word != "" ]
return wPalindromes
print(getPalindromesFromStr("Lol, this is a gag, I didn’t laugh so much in a long time"))
解决方案
推荐阅读
- class - 如何强制 Dart/Flutter 重用具有相同属性的相同类
- swift - 如何检查特定日期在两个日期之间发生了多少次?
- c++ - 赋值运算符(+= 和 =)之间的区别
- android - WorkManager 将失败的作业保留多长时间?
- postgresql - 幂等插入,如果值是新的,则引发错误
- python - 在数据框单元格中搜索关键字
- google-sheets - 从另一个日期范围(项目时间)存在于另一个日期范围(月)内的另一个工作表中复制数据的方法
- postgresql - 在postgres中首先删除外部表和主键表
- php - 使用 jquery 单击按钮获取公司详细信息
- hyperledger-fabric - Fabric sdk 连接配置文件添加新组织并安装链码