중복 문자 (테스트를 위해 'd'와 'r'로 시작)를 포함하는 목록에서 모든 단어를 삭제하려고하지만 원하는 모든 문자를 확인할 수 없습니다.
a = ["word","worrd","worrrd","wordd"]
alpha = ['d','r']
i = 0
x = 0
while x in range(0, len(alpha)):
while i in range(0, len(a)):
if a[i].count(alpha[x]) > 1:
del(a[i])
i = i - 1
else:
i = i + 1
x = x + 1
print(a)
당신은 그것을 잘하고 있지만 x의 while 루프에서 "i"의 값을 재설정하는 것을 잊었습니다.
a = ["word","worrd","worrrd","wordd"]
alpha = ['d','r']
x = 0
while x in range(0, len(alpha)):
# i should be reset here
i = 0
while i in range(0, len(a)):
if a[i].count(alpha[x]) > 1:
del(a[i])
i = i - 1
else:
i = i + 1
x = x + 1
print(a)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다