473,508 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Needing python experts to help with a problem

gms
Hello,
I have the following list:

[{'count': u'2', 'manu': <Manufacturer: Manu1>}, {'count': u'4',
'manu': <Manufacturer: Manu2>}, {'count': u'2', 'manu': <Manufacturer:
Manu3>}, {'count': u'2', 'manu': <Manufacturer: Manu2>}]

My current list currently contains four dictionaries. They are:

{'count': u'2', 'manu': <Manufacturer: Manu1>}
{'count': u'4', 'manu': <Manufacturer: Manu2>}
{'count': u'2', 'manu': <Manufacturer: Manu3>}
{'count': u'2', 'manu': <Manufacturer: Manu2>}

I need to create a list for each specific Manufacturer. Since I have
two dictionaries that have 'Manu2' as it's manufacturer. I will need
some code that will create the following from the list above:

[{'count': u'2', 'manu': <Manufacturer: Manu1>}]
[{'count': u'4', 'manu': <Manufacturer: Manu2>},{'count': u'2',
'manu': <Manufacturer: Manu2>}]
[{'count': u'2', 'manu': <Manufacturer: Manu3>}]

The reason for this is because I want to send one email to each
manufacturer. In this case I would send two emails to Manu2 because I
have two dictionaries that have Manu2 as the manufacturer. That is
why I need to create a separate list for each manufacturer.

Any help on on how best to do this would be greatly appreciated!

Thanks
Jun 27 '08 #1
2 1092
CM
On Jun 7, 12:51 am, gms <esug...@gmail.comwrote:
Hello,
I have the following list:

[{'count': u'2', 'manu': <Manufacturer: Manu1>}, {'count': u'4',
'manu': <Manufacturer: Manu2>}, {'count': u'2', 'manu': <Manufacturer:
Manu3>}, {'count': u'2', 'manu': <Manufacturer: Manu2>}]

My current list currently contains four dictionaries. They are:

{'count': u'2', 'manu': <Manufacturer: Manu1>}
{'count': u'4', 'manu': <Manufacturer: Manu2>}
{'count': u'2', 'manu': <Manufacturer: Manu3>}
{'count': u'2', 'manu': <Manufacturer: Manu2>}

I need to create a list for each specific Manufacturer. Since I have
two dictionaries that have 'Manu2' as it's manufacturer. I will need
some code that will create the following from the list above:

[{'count': u'2', 'manu': <Manufacturer: Manu1>}]
[{'count': u'4', 'manu': <Manufacturer: Manu2>},{'count': u'2',
'manu': <Manufacturer: Manu2>}]
[{'count': u'2', 'manu': <Manufacturer: Manu3>}]

The reason for this is because I want to send one email to each
manufacturer. In this case I would send two emails to Manu2 because I
have two dictionaries that have Manu2 as the manufacturer. That is
why I need to create a separate list for each manufacturer.

Any help on on how best to do this would be greatly appreciated!

Thanks
I'm not expert, but it just seems that this structure is overly
complex. What is your goal, and what information do you want to
associate with each manufacturer? Couldn't you simplify this
this section:
{'count': u'2', 'manu': <Manufacturer: Manu1>}
{'count': u'4', 'manu': <Manufacturer: Manu2>}
{'count': u'2', 'manu': <Manufacturer: Manu3>}
{'count': u'2', 'manu': <Manufacturer: Manu2>}
to something like:

manu_dict = { Manu1:[2], Manu2:[4,2], Manu3:[2] }

Jun 27 '08 #2
CM wrote:
On Jun 7, 12:51 am, gms <esug...@gmail.comwrote:
>Hello,
I have the following list:

[{'count': u'2', 'manu': <Manufacturer: Manu1>}, {'count': u'4',
'manu': <Manufacturer: Manu2>}, {'count': u'2', 'manu': <Manufacturer:
Manu3>}, {'count': u'2', 'manu': <Manufacturer: Manu2>}]
....

This sounds like a homework assignment. If you're having trouble
with this, sending mail from Python is really going to be a headache
for you.

You want something like

inlist = [{'count': u'2', 'manu': <Manufacturer: Manu1>}, {'count': u'4',
'manu': <Manufacturer: Manu2>}, {'count': u'2', 'manu': <Manufacturer:
Manu3>}, {'count': u'2', 'manu': <Manufacturer: Manu2>}]
outdict = {}
for mandict in inlist :
if not outdict.has_key(mandict[manu]) # if first for this manu
outdict[mandict[manu]] = [] # make empty list
outdict[mandict[manu]].append(mandict) # append entry to list

You now have the desired result in a dictionary, which you can convert to a list
if you like.

If it's a production job, and the number of manufacturers is large,
you're probably better off using a database like MySQL, or some
mail merge program.

John Nagle
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
33326
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
7
2053
by: stormslayer | last post by:
Folks: I've been considering a shift to python. I currently use c++builder (borland) or perl. I do computational models / statistics programming, and was interested in python b/c it a. has...
2
2851
by: Roose | last post by:
With some googling I have found these resources: http://docs.python.org/ext/win-dlls.html http://www.python.org/doc/faq/windows.html I have a large Win32/MFC/C/C++ application that has an...
114
9691
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
20
4023
by: Xah Lee | last post by:
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the “sort” method. For example: ...
11
1912
by: blah | last post by:
Need python Pro at newtopython@googlegroups.com , if u wanna help, plz reply to that address. We are python beginners. need a real good Python Programmer for Help. TIA!! -- * Posted with...
40
2685
by: =?iso-8859-1?B?QW5kcuk=?= | last post by:
I'm really annoyed at Python - and not for the reasons already mentioned on this list. Everyone know that programming is supposed to be a dark art, nearly impossible to learn. Computer code is...
0
7120
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
1553
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.