Vấn đề là any[]
trả về True
nếu bất kỳ một trong các phần tử nào trong ITBEBER là True
, vì vậy mã của bạn liên tục lặp lại miễn là câu trả lời không bằng tất cả các chuỗi trong ____ 10 có lẽ trái ngược với những gì bạn muốn xảy ra. Đây là một cách để sử dụng nó dừng hoặc phá vỡ vòng lặp nếu câu trả lời phù hợp với bất kỳ chuỗi nào:one of the elements in the iterable is True
, so your code keeps looping as long as the answer isn't equal to all the strings in
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
0—which is probably the opposite of what you want to happen. Here's a way to use it that stops or breaks-out of the loop if the answer matches any of the strings:months_list = ["January", "February", "March", "April", "May", "June", "July"]
while True:
answer = raw_input["Month? "]
if any[item.lower[] == answer.lower[] for item in months_list]:
break
print["Sorry, didn't recognize your answer, try again"]
Như những người khác đã chỉ ra, trong khi việc sử dụng toán tử
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
1 của Python sẽ đơn giản hơn, nhưng theo cách đó vẫn dẫn đến tìm kiếm tuyến tính, O [N], được thực hiện, vì vậy một cách tiếp cận thậm chí còn tốt hơn [nhanh hơn] sẽ là sử dụng months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
2 của thấp hơn CASED months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
3, sẽ sử dụng tra cứu dựa trên bảng băm, O [1], thay vì tìm kiếm tuyến tính:O[n], being performed…so an even better [faster] approach would be to use a months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
2 of lower-cased months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
3, which would utilize a hash table based look-up, O[1], instead of a linear search:months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
Tinh chỉnh hơn nữa
Tùy thuộc vào bản chất của các chuỗi liên quan và lý do tại sao bạn so sánh chúng, có thể tốt hơn là sử dụng phương thức chuỗi
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
4 thay vì months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
5 để thực hiện so sánh chuỗi vô dụng. Chúng tôi được cung cấp một chuỗi và nhiệm vụ của chúng tôi là kiểm tra xem chuỗi có chứa các phần tử từ danh sách không.
Example:
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True
Cách tiếp cận ngây thơ kiểm tra từng từ trong chuỗi
Ở đây chúng tôi đang chia chuỗi thành danh sách các từ và sau đó khớp từng từ của danh sách này với danh sách các từ đã hiện tại chúng tôi muốn kiểm tra.
Python3
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
6months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7 months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
8months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
9months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7 Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True1
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True2223
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True4
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True5
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True6
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True7
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True8
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True9
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element0
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True6
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True7
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element3
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True9
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element6
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element7
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element9
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True0
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True1
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True2
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True4
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True6
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
1 The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True8
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True9
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True1
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
1 The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True3
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True4
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True6
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True9
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True0
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True2
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True3
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True0
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True2
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True3
any[]
1The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True9
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True6
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True7
any[]
5The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True1
any[]
7any[]
1
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True9
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True6
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True7
True
2The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True1
Output:
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element
Sử dụng danh sách hiểu & nbsp; để kiểm tra xem chuỗi có chứa phần tử từ danh sách không to check if string contains element from list
Vấn đề này có thể được giải quyết bằng cách sử dụng danh sách hiểu, trong đó, chúng tôi kiểm tra danh sách và cả với các phần tử chuỗi nếu chúng tôi có thể tìm thấy một trận đấu và trả về true, nếu chúng tôi tìm thấy một và sai là không sử dụng các câu lệnh có điều kiện. & NBSP;
Python3
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
6months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7 months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
8months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
9months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7 Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True1
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True2223
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True4
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True5
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True6
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True7
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True8
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True9
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element0
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True6
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True7
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element3
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True9
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element6
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True6
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
1 The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True8
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True9
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True1
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
1 The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True3
Output:
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True
The original string : There are 2 apples for 4 persons
The original list : ['apples', 'oranges']
Does string contain any list element : True
4The original string : There are 2 apples for 4 persons
The original list : ['apples', 'oranges']
Does string contain any list element : True
5 The original string : There are 2 apples for 4 persons
The original list : ['apples', 'oranges']
Does string contain any list element : True
6months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7The original string : There are 2 apples for 4 persons
The original list : ['apples', 'oranges']
Does string contain any list element : True
9 to check if
string contains element from list
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True2
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True3
any[]
1Python3
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
6months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7 months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
8months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
9months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7 Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True1
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True2223
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True4
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True5
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True6
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True7
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True8
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True9
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element0
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True6
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True7
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element3
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True9
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element6
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True6
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
1 The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True8
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True9
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True1
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
1 The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True3
Output:
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True
The original string : There are 2 apples for 4 persons
The original list : ['apples', 'oranges']
Does string contain any list element : True
4The original string : There are 2 apples for 4 persons
The original list : ['apples', 'oranges']
Does string contain any list element : True
5 The original string : There are 2 apples for 4 persons
The original list : ['apples', 'oranges']
Does string contain any list element : True
6months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7The original string : There are 2 apples for 4 persons
The original list : ['apples', 'oranges']
Does string contain any list element : True
9
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True2
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True3
any[]
1Python3
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
6months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7 months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
8months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
9months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7 Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True1
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True2223
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True4
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True5
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True6
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True7
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True8
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True9
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element0
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True6
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True7
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element3
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True9
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] String contains the list element6
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
82months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
84months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
85months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True4
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True6
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
1 The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True8
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True9
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True5
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
94months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
96The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True3
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
98The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True4
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
85Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True9
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True3
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True5
Input: String: Geeks for Geeks is one of the best company. List: ['Geeks', 'for'] Output: Does string contain any list element : True05
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True3
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
98The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True9
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
82months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
7True
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True9
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True5
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True1
months = set[month.lower[] for month in ["January", "February", "March", "April",
"May", "June", "July"]]
while True:
answer = raw_input["Month? "]
if answer.lower[] in months:
break
print["Sorry, didn't recognize your answer, try again"]
1 The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True3
Output:
The original string : There are 2 apples for 4 persons The original list : ['apples', 'oranges'] Does string contain any list element : True