Re: lists and dictionaries



Thank you to all of you guys.
It's exactly I was looking for.
You provide scant information for this task. For example, is the
new list ordered or unordered? Can the list corresponding to the
'transports' key contain duplicates?
unordered is fine.. I will be storing it in DB from that list.
It should not happen to get 'transports' duplicates in my application.
It's for testing domains where are running SIP servers.

Lada



Bart Ogryczak wrote:
On 12 jul, 04:49, anethema <jefish...@xxxxxxxxx> wrote:
li = [ {'index': 0, 'transport': 'udp', 'service_domain':
'dp0.example.com'},
{'index': 1, 'transport': 'udp', 'service_domain':
'dp1.example.com'},
{'index': 0, 'transport': 'tcp', 'service_domain':
'dp0.example.com'},
{'index': 1, 'transport': 'tcp', 'service_domain':
'dp1.example.com'}]
I like this solution:

[{ 'transports' : [d['transport'] for d in li if
d['service_domain'] == dom],
'service_domain': dom,
} for dom in set(d2['service_domain'] for d2 in li)]

merely because it takes one line. Humorously enough, it appears to be
twice as efficient,

Correct me if I´m wrong, that is a O(n**2) solution, to O(n) problem.


.



Relevant Pages

  • Re: Count x2 Appearance of Numeric Value in any Row
    ... number that appears twice and only twice in a row but can have multiple x2 ... Looking for criterion "0": a summed count of 2 should be returned. ... you know if there are any dupes at all: ... Not looking for duplicates as such, ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Merging two spreadsheets, avoiding duplicates?
    ... I'm afraid that what i'm looking for is not what you just described. ... See how Ribas - John Smith - js@ribas.com exists twice? ... Ribas or two John Smiths is fine. ... > The email column C has no duplicates to filter or tag. ...
    (microsoft.public.excel)
  • [PATCH] VIA Chrome integrated camera controller driver includes headers multiple times
    ... The VIA Chrome integrated camera controller driver includes both ... 'linux/pci.h' and 'linux/device.h' twice. ... This gets rid of the duplicates. ...
    (Linux-Kernel)
  • Several duplicate items in Menus listing.
    ... twice. ... Some duplicates have suffix "", ... Full disclosure dept.: I think at one point ol' Loser User was copying ...
    (microsoft.public.pocketpc)
  • Re: Unwanted fields in a distribution list
    ... my contacts come up twice. ... This is correct behavior. ... Since a FAX number is also an electronic address and Outlook can work with a number of FAX programs to send faxes, the address book view will show the FAX number as well. ... and do not have duplicates, and when initially mapping these fields ...
    (microsoft.public.outlook)