我需要取一个字符串,例如 AABCAAADA 并将其拆分为给定数量的字符串,比如说 3(但这可以是任何东西)。然后,在这些字符串中,删除重复的字符。对于给定的示例,此代码的输出应为 AB、CA 和 AD。
我的代码为最后一个示例生成 DA,我不明白为什么会这样。
import textwrap
def splitToT(string, number):
wordsList = list(textwrap.wrap(string,number))
for word in wordsList:
t = word
makeU(t)
def makeU(t):
list1 = list(t)
list2 = list(t)
print"list1 = "
print list1
print"list2 = "
print list2
for l1e in list1:
print "element from list1"
print l1e
count = 0
print"COUNT RESET"
for l2e in list2:
print "\t Element in list2"
print("\t" + l2e)
if str(l1e) == str(l2e):
count = count+1
print count
if count >= 2:
print("removing element")
print l2e
list2.remove(l2e)
print"\tlist 2 is now"
print list2
print "LIST2 IS:"
print list2
print("-----")
def main():
n = 3
S = 'AABCAAADA'
splitToT(S, n)
if __name__ == "__main__":
main()
海绵宝宝撒
HUWWW
跃然一笑
相关分类