Đây là những gì tôi đã tìm kiếm trực tuyến. Tuy nhiên, thật không may, không tìm thấy trực tuyến, nhưng trong khi thử nghiệm trên thông dịch viên Python.
>>> case = "caseCamel"
>>> label = "Case Camel"
>>> list = ["apple", "banana"]
>>>
>>> [case or label] in list
False
>>> list = ["apple", "caseCamel"]
>>> [case or label] in list
True
>>> [case and label] in list
False
>>> list = ["case", "caseCamel", "Case Camel"]
>>> [case and label] in list
True
>>>
Và nếu bạn có một danh sách các biến được tổ chức trong một sublist variable
>>>
>>> list = ["case", "caseCamel", "Case Camel"]
>>> label = "Case Camel"
>>> case = "caseCamel"
>>>
>>> sublist = ["unique banana", "very unique banana"]
>>>
>>> # example for if any [at least one] item contained in superset [or statement]
...
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
False
>>>
>>> sublist[0] = label
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>> # example for whether a subset [all items] contained in superset [and statement]
...
>>> # a bit of demorgan's law
...
>>> next[[False for item in sublist if item not in list], True]
False
>>>
>>> sublist[1] = case
>>>
>>> next[[False for item in sublist if item not in list], True]
True
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>>
Cải thiện bài viết
Lưu bài viết
Cải thiện bài viết
Lưu bài viết
Đọc
Input : lst = [[1, 1, 1, 2], [2, 3, 4], [1, 2, 3], [4, 5, 6]] list_search = [4, 5, 6] Output: True Input : lst = [[5, 6, 7], [12, 54, 9], [1, 2, 3]] list_search = [4, 12, 54] Output: False
Bàn luận
Đưa ra một danh sách các danh sách, nhiệm vụ là kiểm tra xem danh sách có tồn tại trong danh sách nhất định các danh sách không.Counter The most concise and readable way to find whether a list exists in list of lists is using Counter.
Python3
Hãy để thảo luận về những cách nhất định trong đó nhiệm vụ này được thực hiện. & NBSP;
Input
______7
sublist variable
5=
sublist variable
7
>>>
>>> list = ["case", "caseCamel", "Case Camel"]
>>> label = "Case Camel"
>>> case = "caseCamel"
>>>
>>> sublist = ["unique banana", "very unique banana"]
>>>
>>> # example for if any [at least one] item contained in superset [or statement]
...
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
False
>>>
>>> sublist[0] = label
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>> # example for whether a subset [all items] contained in superset [and statement]
...
>>> # a bit of demorgan's law
...
>>> next[[False for item in sublist if item not in list], True]
False
>>>
>>> sublist[1] = case
>>>
>>> next[[False for item in sublist if item not in list], True]
True
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>>
5>>>
>>> list = ["case", "caseCamel", "Case Camel"]
>>> label = "Case Camel"
>>> case = "caseCamel"
>>>
>>> sublist = ["unique banana", "very unique banana"]
>>>
>>> # example for if any [at least one] item contained in superset [or statement]
...
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
False
>>>
>>> sublist[0] = label
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>> # example for whether a subset [all items] contained in superset [and statement]
...
>>> # a bit of demorgan's law
...
>>> next[[False for item in sublist if item not in list], True]
False
>>>
>>> sublist[1] = case
>>>
>>> next[[False for item in sublist if item not in list], True]
True
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>>
0>>>
>>> list = ["case", "caseCamel", "Case Camel"]
>>> label = "Case Camel"
>>> case = "caseCamel"
>>>
>>> sublist = ["unique banana", "very unique banana"]
>>>
>>> # example for if any [at least one] item contained in superset [or statement]
...
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
False
>>>
>>> sublist[0] = label
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>> # example for whether a subset [all items] contained in superset [and statement]
...
>>> # a bit of demorgan's law
...
>>> next[[False for item in sublist if item not in list], True]
False
>>>
>>> sublist[1] = case
>>>
>>> next[[False for item in sublist if item not in list], True]
True
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>>
9____10____Input : lst = [[1, 1, 1, 2], [2, 3, 4], [1, 2, 3], [4, 5, 6]] list_search = [4, 5, 6] Output: True Input : lst = [[5, 6, 7], [12, 54, 9], [1, 2, 3]] list_search = [4, 12, 54] Output: False1
import
3Bạn có thể kiểm tra xem một danh sách có trong danh sách khác không?
Bất kỳ [] phương thức khác Một phương thức khác là bất kỳ [] mà chúng ta có thể sử dụng để kiểm tra xem danh sách có chứa bất kỳ phần tử nào của một phương pháp khác không.
Bạn có thể sử dụng == cho các danh sách trong Python không?
Phương thức python sort [] và == Toán tử để so sánh các danh sách chúng ta có thể câu lạc bộ phương thức python sort [] với toán tử == để so sánh hai danh sách. Phương thức python sort [] được sử dụng để sắp xếp các danh sách đầu vào với mục đích nếu hai danh sách đầu vào bằng nhau, thì các phần tử sẽ nằm ở cùng một vị trí chỉ mục.
Cải thiện bài viết
collections
2Input
9=
0=
1=
2
=
3collections
1
collections
2Input
9=
0=
8=
2
Lưu bài viếtMethod #2: Using in
Python3
Input
______7
sublist variable
5=
sublist variable
7
>>>
>>> list = ["case", "caseCamel", "Case Camel"]
>>> label = "Case Camel"
>>> case = "caseCamel"
>>>
>>> sublist = ["unique banana", "very unique banana"]
>>>
>>> # example for if any [at least one] item contained in superset [or statement]
...
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
False
>>>
>>> sublist[0] = label
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>> # example for whether a subset [all items] contained in superset [and statement]
...
>>> # a bit of demorgan's law
...
>>> next[[False for item in sublist if item not in list], True]
False
>>>
>>> sublist[1] = case
>>>
>>> next[[False for item in sublist if item not in list], True]
True
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>>
5>>>
>>> list = ["case", "caseCamel", "Case Camel"]
>>> label = "Case Camel"
>>> case = "caseCamel"
>>>
>>> sublist = ["unique banana", "very unique banana"]
>>>
>>> # example for if any [at least one] item contained in superset [or statement]
...
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
False
>>>
>>> sublist[0] = label
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>> # example for whether a subset [all items] contained in superset [and statement]
...
>>> # a bit of demorgan's law
...
>>> next[[False for item in sublist if item not in list], True]
False
>>>
>>> sublist[1] = case
>>>
>>> next[[False for item in sublist if item not in list], True]
True
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>>
0>>>
>>> list = ["case", "caseCamel", "Case Camel"]
>>> label = "Case Camel"
>>> case = "caseCamel"
>>>
>>> sublist = ["unique banana", "very unique banana"]
>>>
>>> # example for if any [at least one] item contained in superset [or statement]
...
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
False
>>>
>>> sublist[0] = label
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>> # example for whether a subset [all items] contained in superset [and statement]
...
>>> # a bit of demorgan's law
...
>>> next[[False for item in sublist if item not in list], True]
False
>>>
>>> sublist[1] = case
>>>
>>> next[[False for item in sublist if item not in list], True]
True
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>>
9____10____Input : lst = [[1, 1, 1, 2], [2, 3, 4], [1, 2, 3], [4, 5, 6]] list_search = [4, 5, 6] Output: True Input : lst = [[5, 6, 7], [12, 54, 9], [1, 2, 3]] list_search = [4, 12, 54] Output: False1
import
3Bạn có thể kiểm tra xem một danh sách có trong danh sách khác không?
Bất kỳ [] phương thức khác Một phương thức khác là bất kỳ [] mà chúng ta có thể sử dụng để kiểm tra xem danh sách có chứa bất kỳ phần tử nào của một phương pháp khác không.
=
3collections
1
collections
2Input
9=
0=
1=
2
Bạn có thể sử dụng == cho các danh sách trong Python không?Method #3: Using any
Python3
Input
______7
Các
collections
3
>>>
>>> list = ["case", "caseCamel", "Case Camel"]
>>> label = "Case Camel"
>>> case = "caseCamel"
>>>
>>> sublist = ["unique banana", "very unique banana"]
>>>
>>> # example for if any [at least one] item contained in superset [or statement]
...
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
False
>>>
>>> sublist[0] = label
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>> # example for whether a subset [all items] contained in superset [and statement]
...
>>> # a bit of demorgan's law
...
>>> next[[False for item in sublist if item not in list], True]
False
>>>
>>> sublist[1] = case
>>>
>>> next[[False for item in sublist if item not in list], True]
True
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>>
76>>>
>>> list = ["case", "caseCamel", "Case Camel"]
>>> label = "Case Camel"
>>> case = "caseCamel"
>>>
>>> sublist = ["unique banana", "very unique banana"]
>>>
>>> # example for if any [at least one] item contained in superset [or statement]
...
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
False
>>>
>>> sublist[0] = label
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>> # example for whether a subset [all items] contained in superset [and statement]
...
>>> # a bit of demorgan's law
...
>>> next[[False for item in sublist if item not in list], True]
False
>>>
>>> sublist[1] = case
>>>
>>> next[[False for item in sublist if item not in list], True]
True
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>>
77>>>
>>> list = ["case", "caseCamel", "Case Camel"]
>>> label = "Case Camel"
>>> case = "caseCamel"
>>>
>>> sublist = ["unique banana", "very unique banana"]
>>>
>>> # example for if any [at least one] item contained in superset [or statement]
...
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
False
>>>
>>> sublist[0] = label
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>> # example for whether a subset [all items] contained in superset [and statement]
...
>>> # a bit of demorgan's law
...
>>> next[[False for item in sublist if item not in list], True]
False
>>>
>>> sublist[1] = case
>>>
>>> next[[False for item in sublist if item not in list], True]
True
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>>
78collections
2Input
9=
0=
8=
2
=
3collections
1
collections
2Input
9=
0=
1=
2
Phương pháp số 4: Sử dụng phương thức Count []
Python3
Input
______7
sublist variable
5=
sublist variable
7
>>>
>>> list = ["case", "caseCamel", "Case Camel"]
>>> label = "Case Camel"
>>> case = "caseCamel"
>>>
>>> sublist = ["unique banana", "very unique banana"]
>>>
>>> # example for if any [at least one] item contained in superset [or statement]
...
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
False
>>>
>>> sublist[0] = label
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>> # example for whether a subset [all items] contained in superset [and statement]
...
>>> # a bit of demorgan's law
...
>>> next[[False for item in sublist if item not in list], True]
False
>>>
>>> sublist[1] = case
>>>
>>> next[[False for item in sublist if item not in list], True]
True
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>>
5>>>
>>> list = ["case", "caseCamel", "Case Camel"]
>>> label = "Case Camel"
>>> case = "caseCamel"
>>>
>>> sublist = ["unique banana", "very unique banana"]
>>>
>>> # example for if any [at least one] item contained in superset [or statement]
...
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
False
>>>
>>> sublist[0] = label
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>> # example for whether a subset [all items] contained in superset [and statement]
...
>>> # a bit of demorgan's law
...
>>> next[[False for item in sublist if item not in list], True]
False
>>>
>>> sublist[1] = case
>>>
>>> next[[False for item in sublist if item not in list], True]
True
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>>
0>>>
>>> list = ["case", "caseCamel", "Case Camel"]
>>> label = "Case Camel"
>>> case = "caseCamel"
>>>
>>> sublist = ["unique banana", "very unique banana"]
>>>
>>> # example for if any [at least one] item contained in superset [or statement]
...
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
False
>>>
>>> sublist[0] = label
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>> # example for whether a subset [all items] contained in superset [and statement]
...
>>> # a bit of demorgan's law
...
>>> next[[False for item in sublist if item not in list], True]
False
>>>
>>> sublist[1] = case
>>>
>>> next[[False for item in sublist if item not in list], True]
True
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>>
9____10____Input : lst = [[1, 1, 1, 2], [2, 3, 4], [1, 2, 3], [4, 5, 6]] list_search = [4, 5, 6] Output: True Input : lst = [[5, 6, 7], [12, 54, 9], [1, 2, 3]] list_search = [4, 12, 54] Output: False1
import
3Input : lst = [[1, 1, 1, 2], [2, 3, 4], [1, 2, 3], [4, 5, 6]] list_search = [4, 5, 6] Output: True Input : lst = [[5, 6, 7], [12, 54, 9], [1, 2, 3]] list_search = [4, 12, 54] Output: False37
=
=
1collections
3
>>>
>>> list = ["case", "caseCamel", "Case Camel"]
>>> label = "Case Camel"
>>> case = "caseCamel"
>>>
>>> sublist = ["unique banana", "very unique banana"]
>>>
>>> # example for if any [at least one] item contained in superset [or statement]
...
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
False
>>>
>>> sublist[0] = label
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>> # example for whether a subset [all items] contained in superset [and statement]
...
>>> # a bit of demorgan's law
...
>>> next[[False for item in sublist if item not in list], True]
False
>>>
>>> sublist[1] = case
>>>
>>> next[[False for item in sublist if item not in list], True]
True
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>>
77Input
Input : lst = [[1, 1, 1, 2], [2, 3, 4], [1, 2, 3], [4, 5, 6]] list_search = [4, 5, 6] Output: True Input : lst = [[5, 6, 7], [12, 54, 9], [1, 2, 3]] list_search = [4, 12, 54] Output: False43
=
1
>>>
>>> list = ["case", "caseCamel", "Case Camel"]
>>> label = "Case Camel"
>>> case = "caseCamel"
>>>
>>> sublist = ["unique banana", "very unique banana"]
>>>
>>> # example for if any [at least one] item contained in superset [or statement]
...
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
False
>>>
>>> sublist[0] = label
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>> # example for whether a subset [all items] contained in superset [and statement]
...
>>> # a bit of demorgan's law
...
>>> next[[False for item in sublist if item not in list], True]
False
>>>
>>> sublist[1] = case
>>>
>>> next[[False for item in sublist if item not in list], True]
True
>>>
>>> next[[True for item in sublist if next[[True for x in list if x == item], False]], False]
True
>>>
>>>
86collections
2
Input : lst = [[1, 1, 1, 2], [2, 3, 4], [1, 2, 3], [4, 5, 6]] list_search = [4, 5, 6] Output: True Input : lst = [[5, 6, 7], [12, 54, 9], [1, 2, 3]] list_search = [4, 12, 54] Output: False37
=
=
8Input
9
Input : lst = [[1, 1, 1, 2], [2, 3, 4], [1, 2, 3], [4, 5, 6]] list_search = [4, 5, 6] Output: True Input : lst = [[5, 6, 7], [12, 54, 9], [1, 2, 3]] list_search = [4, 12, 54] Output: False52