删除重复字符的位置
你好,我的程序应该打印输入的字符串的长度,只有在不重复的情况下才打印放入列表中的字符,然后打印这些字符的位置列表。我相信有很多方法可以做到这一点,然而,这是我能想到的唯一方法,只需设置另一个变量并将该变量添加到列表中,然而在添加它之后,我需要找到一种方法来删除重复字符的位置。谢谢。
选择 | 换行 | 行号
- string = raw_input("Enter string->")
- length = len(string)
- indx = 0
- z = 0
- print "The length of the string is", length
- chars_stored = []
- frequencysite = []
- while length > indx:
- if string[indx] == chars_stored:
- indx = indx + 1
- elif string[indx] != chars_stored:
- chars_stored = chars_stored + [(string[indx])]
- frequencysite = frequencysite + [z]
- z = z + 1
- indx = indx + 1
- print chars_stored
- print frequencysite