Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

this is the function which gets tuple

orderList = self.product.getOrderList()

here I am looking for the same ones in the tuple from now on

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can map your lists to tuples and use 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).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading