0

I want to make a tool to help me planning the production.

I have table of 2000 products, and roughly 1500 different model plates (I am working in a foundry). Each model plate has up to 10 different (or same) models on it (models = products). When I get the order I break it down and end up with list such as:

product1 = 200
product2 = 500
product3 = 300

where productX is code and numbers are needed ammounts.

I'd like to make a tool that would scan through the model plates and find me the plates that have most of the ordered pieces on it. I would also like to do it in Python because I am familiar with it and I have wrote programs that interact with our database before.

Now I hope that I explained it well enough :)

ch1zra
  • 171
  • 15
  • Please provide more samples on what you need. Certain use cases – Artsiom Rudzenka Nov 06 '12 at 07:55
  • 2
    Welcome to Stack Overflow! We encourage you to [research your questions](http://stackoverflow.com/questions/how-to-ask). If you've [tried something already](http://whathaveyoutried.com/), please add it to the question - if not, research and attempt your question first, and then come back. –  Nov 06 '12 at 07:55
  • @ Artsion It's a bit hard to explain... I got some idea with regex that I'll try, and if I fail i will come back and try to explain better :] – ch1zra Nov 06 '12 at 08:05
  • You may find that making it so others can understand your problem means you actually find a solution yourself! Also, I'm pretty sure regex **is not** the way to go... – Jon Clements Nov 06 '12 at 08:53

1 Answers1

2

"highest match" can be interpreted in two ways:

Item with maximum numeric value

Use sorted on the right hand side of each line:

>>> l
['product1 = 200', 'product2 = 500', 'product3 = 300']
>>> sorted(l, key=lambda x:int(x.split('=')[1]))
['product1 = 200', 'product3 = 300', 'product2 = 500']
>>> sorted(l, key=lambda x:int(x.split('=')[1]), reverse=True)
['product2 = 500', 'product3 = 300', 'product1 = 200']

Most frequent item

The Python Counter is probably the data structure you're looking for. Insert your elements to a sequence, create a Counter from it, and extract the most_common() element.

>>> from collections import Counter
>>> l=['a','a','a','b','c']
>>> c=Counter(l)
>>> c.most_common()
[('a', 3), ('c', 1), ('b', 1)]
>>> c.most_common()[0][0]
'a'
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
  • I can't use Counter because I am using Python 2.6.2 atm. I will look into it, and I am partialy on to solution, at least into solution that will allow me to forward data to excel and there manipulate it. I am hoping to get some progress today if time allows me to code... – ch1zra Nov 07 '12 at 08:18