我已阅读并重新阅读列表解析和循环,我想这些不是我认为的那些。用于删除列表中的多个元素的用户输入
我试图通过将垃圾变成列表,排序,删除垃圾,按照用户的定义,在一堆垃圾中找到信息。用户输入一个字符,所有匹配的字符应该被删除。重复。
但是,它只能删除其中一个匹配字符,而不是全部。我相信问题在于我打电话重新开始功能的方式,但我想功能(和类呼叫这个问题)不像我认为的那样工作
这里离我已经很近了小时:(我完全小白在此之后,这样下去容易对我好吗谢谢
junk = """
(+*]_}%+(%[{)]({#[+$&&[^@{&#[email protected]%)!+&}[email protected][email protected][+&_*!$(+#*%[email protected]{{^**{)(]*$(}+
!$%}$$}[email protected]^$$%{}{#!(%[]$!*}+(]!%{(^{&^{$[$)]&&^+{+%!#[([%^!{]]#^@!{#(&]@_$*_&!%(!
+_+}%@#{_}^#*)%*(*}*![}[%_[[^@$&%)([*{_${)$^^_!+}{)!)@_[*$_}*}$#[+}{]*+!^])}&{+#
[email protected]!^*@}!}&{]*#^@}_[)}#@%!_*#!$}!)[(${+^&!{[&&&*[{}+*+(#+_[}{$$)#([*!)%@^%_]#%$$
(++^+&)}*_&%@#[^^+^&@_%]+$%$#$*)@!(]*[email protected]]}%$$}$(#$&^(%[*([&]*^&}(!#{&_}^(*{(+$#}}
(&_+][&[email protected])$&$&^[_$(++$^}]&^^*(+*!&#_$]*[email protected]!]+{%^_*+!&}@$!#^{+_#([[email protected](((*+)[()__}(^
@)](+[$*_(]*$[[&@^(_*#(*&!^{+]_%)_)^[}@]#]%#@+^+[%{_*{!)}#[email protected]#)_$!_(!*+#}%%}+$&$[
%&]!{{%*_!*}&)}$**_{*!#%[[#]!](^^$![#[[*}%(_#^^!%))!_^@)@**@}}(%%{#*%@(((]^%^![&
}!)$]&($)@](+(#{$)_%^%_^^#][{*[)%}+[##(##^{$}^]#&(&*{)%)&][&{]&#]}[[^^&[!#}${@_(
#@}&$[[%]_&$+)$!%{(}$^$}*
"""
junklist = list(junk)
def find():
junklist.sort()
print junklist
x = str(raw_input("what do you want to remove from the list?> "))
return x
def deleteChars(x):
while len(junklist) > 0:
if x in junklist:
junklist.remove(x)
find()
else:
print "not in junklist"
find()
x =find()
我无法弄清楚在哪里把我的while循环做出这个递归。结果发生的是我继续经历同样的循环,所以当我们创建列表(a)时,我们基本上从垃圾列表中删除的字符都回来了......我想这是一个全新的问题?感谢您的帮助。 – shuashock 2014-09-03 06:46:20