[英]in Python, I can't seem to find the same items in a list
tuple= [['nike airjordan kahverengi', 42, 6],['nike airjordan sarı', 42, 10], ['nike airjordan mavi', 42, 8],['nike airjordan yeşil', 42, 9] ['nike airjordan sarı', 42, 10]]
def getOrderList(self):
orderSplit = ''.join(self.orderText).splitlines()
productList = []
for idx, i in enumerate(orderSplit, start = 0):
if(idx > self.starting_point):
if i == '@':
break
else:
productList.append([i.rstrip(i[-3:]), int(i[-2:]),idx])
return productList
這是獲得元組的 function
orderList = self.product.getOrderList()
在這里我從現在開始在元組中尋找相同的
您可以 map 您的列表到元組並使用collections.Counter
:
lsts = [['nike airjordan kahverengi', 42, 6],['nike airjordan sarı', 42, 10],
['nike airjordan mavi', 42, 8],['nike airjordan yeşil', 42, 9],
['nike airjordan sarı', 42, 10]]
from collections import Counter
counts = Counter(map(tuple, lsts))
for k,v in counts.items():
print(list(k), 'appears', v, 'time(s).')
Output:
['nike airjordan kahverengi', 42, 6] appears 1 time(s).
['nike airjordan sarı', 42, 10] appears 2 time(s).
['nike airjordan mavi', 42, 8] appears 1 time(s).
['nike airjordan yeşil', 42, 9] appears 1 time(s).
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.