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 2 1089
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] }
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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
|
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:
...
|
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...
|
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...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
| |