인쇄 "는"올바른
y = 'albumjcker' # all characters inside "lumberjack"
s = 'lumberjack'
for x in s:
if any(x in alpha for alpha in y):
print x
트릭을
시도를해야한다 :
y = ["a", "b", "c", "l"]
s = ["banana split", "lumberjack"]
for words in s:
for char in y:
if char in words:
print (words)
break
y = ["animal","zoo","potato"]
s = ["The animal farm on the left","I had potatoes for lunch"]
for words in s:
for char in y:
if char in words:
print (words)
break
The animal farm on the left
I had potatoes for lunch
편집
y = ["animal","zoo","potato"]
s = ["The animal farm on the left","I had potatoes for lunch"]
s = list(set(s)) # But NOTE THAT this might change the order of your original list
for words in s:
for char in y:
if char in words:
print (words)
break
순서가 중요 있다면, 난 당신 만
y = ["animal","zoo","potato"]
s = ["The animal farm on the left","I had potatoes for lunch"]
new = []
for x in s:
if x not in new:
new.append(x)
s = new
for words in s:
for char in y:
if char in words:
print (words)
break
을 할 수있는 것 같아요 아마도 단지'의에서 Y는 경우 : –
당신을위한 s' 인쇄 'any '를 가진 루프는 지나치게 복잡해 보입니다. 이런 종류의 논리는 종종 파이썬에서 매우 간단하고 직관적입니다. – keyser
설명이 코드와 너무 다를 때 필요한 것을 추측하기가 어렵습니다. 당신은 "목록"에 관해 글을 쓸 수는 있지만 코드에는 아무 것도 없습니다. –