我的程序除了按随机顺序打印输入外,一切都正确[Python 3,初学者]

我的程序除了按随机顺序打印输入外,一切都正确[Python 3,初学者],python,sorting,random,python-3.x,Python,Sorting,Random,Python 3.x,这个程序的目的是允许用户输入一个字符串,里面隐藏着一个DNA代码。这个程序提取DNA代码(基本上,任何不是ATCG的东西)。它还删除重复的实体。它做的每件事都是正确的,但它以错误的顺序打印出问题。我想请我的导师帮忙,但他目前无法帮助我 input1 = input("Corrupted: ") input2 = "" final = "" for i in input1: if i in "ATGC ": input2 = input2 + i for i in set(input2

这个程序的目的是允许用户输入一个字符串,里面隐藏着一个DNA代码。这个程序提取DNA代码(基本上,任何不是ATCG的东西)。它还删除重复的实体。它做的每件事都是正确的,但它以错误的顺序打印出问题。我想请我的导师帮忙,但他目前无法帮助我

input1 = input("Corrupted: ")
input2 = ""
final = ""
for i in input1:
  if i in "ATGC ":
    input2 = input2 + i
for i in set(input2.split()):
  final = final + i + " "
print("DNA:",final.rstrip())
当它打算输出时:

Corrupted: A1TGcC A?T-G %^AT@CT ATGc #Notice the double ATG (2nd and last one)
DNA: ATGC ATCT ATG #Only one ATG since one is removed.

集合没有任何顺序:

Corrupted: A1TGcC A?T-G %^AT@CT ATGc #This one is in the correct order. How do I get it to stay in the same order?
DNA: ATGC ATG ATCT
要保持秩序,您可以执行以下操作:

>>> print(set.__doc__)
...
Build an unordered collection of unique elements.
对于您的代码而不是字符串连接,您可以使用
regex
,因为类似
input2=input2+i
的内容将被删除


集合没有任何顺序:

Corrupted: A1TGcC A?T-G %^AT@CT ATGc #This one is in the correct order. How do I get it to stay in the same order?
DNA: ATGC ATG ATCT
要保持秩序,您可以执行以下操作:

>>> print(set.__doc__)
...
Build an unordered collection of unique elements.
对于您的代码而不是字符串连接,您可以使用
regex
,因为类似
input2=input2+i
的内容将被删除


集合不有序;使用列表代替?集合不是有序的;或许可以使用列表?@R337不需要抱歉,至少你尝试了一些东西。(大多数初学者只是要求代码);-)@R337不需要抱歉,至少你尝试了一些东西。(大多数初学者只是要求代码);-)