【发布时间】:2021-08-15 07:20:20
【问题描述】:
编写一个 Python 程序,用户可以在其中输入一个值列表和这些值 然后以相同的顺序打印值但不重复。 使用标记“DONE”结束输入列表。
我无法让用户输入他们自己的字符串,我尝试了检查下面的代码。
示例 I/O
Enter strings (end with DONE):
the
old
man
and
the
sea
DONE
Sample Output
Unique list:
the
old
man
and
sea
我的代码:
a = ["Hello","Huitahani","good","Hello","apple","donkey","zebra","apple"]
a = set(a)
result = []
for item in a:
if item not in a:
a.add(item)
result.append(item)
print(a)
【问题讨论】:
-
只检查输入是否已经在列表中,如果不是则追加它。 (并为您的下一个问题付出更多努力。)
-
我未能让用户成为用户插入自己的输入
-
使用 input() 从用户那里获取输入。如果您在geeksforgeeks.org/taking-input-in-python之前从未使用过 input() ,请检查此内容@
-
所以应该是 a = input() ?
-
在下面查看我的答案。
标签: python arrays python-3.x list python-requests