python - Python - gap on exit sequence,error on comparing decimal
问题描述
I enter with numbers out of sequence, subtract the repeated ones, maintaining the order, subtract[']"
of list on exit (is there any more pythonic way for this?). I do not know where I'm going wrong, it fails to compare units of the dozen and a space appears on the output.
a = 1 1 4 4 4 8 8 2 14 14 11 11
expected exit b = 1 4 8 2 14 11
wrong output
b = 1 4 8 2
def repeated(s):
t = []
[t.append(item) for item in s if not t.count(item)]
return t
def remove(s,to_remove):
for x in to_remove:
s = s.replace(x, '')
return s
def main():
a = input('a = ')
print('b = ', (remove(str(repeated(a)), "['],")))
main()
exit()
解决方案
more better use sets
a = set(input().split())
print(' '.join(a))
sets can be contains only unique values, and you don't need to remove values. All values will be unique by default.
推荐阅读
- javascript - 检测 touchmove 事件何时超出目标并重新启动它
- r - 如何将线段添加到谷歌地图
- autohotkey - 无法使用 ahk 运行 ngrok.exe
- javascript - Snatshop 在控制台上返回一个数组,但是当数组中的 find() 是一个元素时,返回 undefined
- php - 没有 404 的 Wordpress 动态子页面
- python - Leetcode 79 BFS 的单词搜索问题
- asp.net - 在 Heroku 上打开成功部署的应用程序时出错
- python - 如何在 AWS Lambda 中使用 Python 调用 HTTP 云函数?
- spring-boot - 通过本地系统从 docker 桌面调用外部服务
- python - 为什么我们将同一个节点连接到两个不同实例的两个不同节点?