python - 删除重复项时留下数字
问题描述
这是我删除字符串中重复字母的代码
word=input()
def dup_find(word):
empty = ""
for character in word:
if character not in empty or character == " ":
empty = empty + character
return empty
当输入为“6969 macaroni”时,输出为“69 macaroni”,但我希望单独留下数字,只删除重复的字母:6969 macaroni。
谢谢您的帮助。
解决方案
这是正确的方法
text="Enter string:"+" "
string=input(text)
def rem_duplicates(string):
x = ""
for letter in string:
if letter.isdigit() or letter not in x or letter == ' ':
x = x + letter
return x
print(rem_duplicates(string))
推荐阅读
- javascript - 如何在 pos 中关闭屏幕时添加弹出动作
- php - 登录 PHP 后登录不重定向到管理索引页面
- matlab - MATLAB 中的谢尔宾斯基三角形
- spring-jdbc - JdbcTemplate 对多个表同时批量更新
- php - Laravel 中所有控制器的通用文件上传
- html - django使用html模板将数据插入数据库
- python - 像“The LJ Speech Dataset”这样的数据集
- python - 为了使用 Python 从 Rust 程序内部调用函数,最佳实践是什么?
- verilog - JK 触发器状态图实现的错误输出
- kubernetes - 如何查看上下文的完整详细信息(如令牌)