[英]write a program in python which does not contain any repeating character from input string . example: A is repeated of a
input is: This is An Example
输入是: This is An Example
Output: This An Exmpl
Output: This An Exmpl
li = input("Enter your Sting")
res = ''
for ch in li:
if ch not in res :
res = res + ch
print(res, end=' ')
li = input("Enter your string")
res = ''
for ch in li.lower():
if ch not in res:
res = res + ch
print(res.title(), end='')
I am sure there will be a more elegant way to do this but for now here is a working version which you could refactor or reduce if needed我相信会有一种更优雅的方式来做到这一点,但现在这里有一个工作版本,如果需要你可以重构或减少
user_input = input("sentance: ")
seen = set()
filtered_words = []
for word in user_input.split():
filtered_word = ""
for char in word:
if char.lower() in seen:
continue
filtered_word += char
seen.add(char.lower())
if filtered_word != "":
filtered_words.append(filtered_word)
print(*filtered_words)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.