I am not very sure about what you are asking for..
But, if it's just a dictionary that you want from the given list then I beleive
the folloeing will work..
>>> x=[['cat',30],['cat',40],['cat',10],['dog',5],['dog',7],['dog',1]]
>>> x= sorted(x)
>>> xdictstart=dict(zip([x[0][0],x[3][0]],[x[0][1],x[3][1]]))
>>> xdictstart
{'dog': 1, 'cat': 10}
And similarly for dictend..
Regards,
Anuj
________________________________
From: "[email protected]" <[email protected]>
To: [email protected]
Sent: Thu, July 22, 2010 7:34:06 PM
Subject: BangPypers Digest, Vol 35, Issue 21
Send BangPypers mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/bangpypers
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of BangPypers digest..."
Today's Topics:
1. [JOB Opening] Juniper Networks (Santhosh Divakar)
2. [JOB Opening] Juniper Networks (Santhosh Divakar)
3. Re: July meetup (Abhishek Mishra)
4. Re: list problem (steve)
5. Re: list problem (Vikram )
6. Re: list problem (Shashwat Anand)
7. Re: list problem (Shashwat Anand)
----------------------------------------------------------------------
Message: 1
Date: Thu, 22 Jul 2010 17:19:24 +0530
From: Santhosh Divakar <[email protected]>
To: Bangalore Python Users Group - India <[email protected]>
Subject: [BangPypers] [JOB Opening] Juniper Networks
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
*Tools Development Engineer*
*Job Location: Bangalore*
* *
*Job Description:*
As a member of the Engineering Software Tools group at Juniper you will be
part of a global team with primary responsibility for the tools
infrastructure of the JUNOS software development environment. You will
design, develop and maintain internal development support tools, including
build and deployment tools, system monitoring, and customizations and
add-ons to development support tools. This position provides the opportunity
to solve a wide variety of different problems, using different tools and
integrating with different tools and environments. You will need to work
closely with different technology teams to determine requirements and
develop effective designs.
*Must Have Skills:*
? 3 to 7 years experience in software development.
? Extensive experience any of the following languages (Perl, Python, C/C++)
? Extensive experience with UNIX-Internals & SHELL scripting.
? Experience with SQL databases. (Knowledge of the DB Basics / Ability to
form and to understand complex SQL Queries)
? Experience across the complete application development lifecycle
including design, prototyping, testing, implementation and deployment.
? Excellent communication skills (both writing and verbal).
? Extremely team oriented, collaborative and flexible.
------------------------------
Message: 2
Date: Thu, 22 Jul 2010 17:19:24 +0530
From: Santhosh Divakar <[email protected]>
To: Bangalore Python Users Group - India <[email protected]>
Subject: [BangPypers] [JOB Opening] Juniper Networks
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
*Tools Development Engineer*
*Job Location: Bangalore*
* *
*Job Description:*
As a member of the Engineering Software Tools group at Juniper you will be
part of a global team with primary responsibility for the tools
infrastructure of the JUNOS software development environment. You will
design, develop and maintain internal development support tools, including
build and deployment tools, system monitoring, and customizations and
add-ons to development support tools. This position provides the opportunity
to solve a wide variety of different problems, using different tools and
integrating with different tools and environments. You will need to work
closely with different technology teams to determine requirements and
develop effective designs.
*Must Have Skills:*
? 3 to 7 years experience in software development.
? Extensive experience any of the following languages (Perl, Python, C/C++)
? Extensive experience with UNIX-Internals & SHELL scripting.
? Experience with SQL databases. (Knowledge of the DB Basics / Ability to
form and to understand complex SQL Queries)
? Experience across the complete application development lifecycle
including design, prototyping, testing, implementation and deployment.
? Excellent communication skills (both writing and verbal).
? Extremely team oriented, collaborative and flexible.
------------------------------
Message: 3
Date: Thu, 22 Jul 2010 18:45:50 +0530
From: Abhishek Mishra <[email protected]>
To: Bangalore Python Users Group - India <[email protected]>
Subject: Re: [BangPypers] July meetup
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hackday this weekend, end of july sounds good.
On Thu, Jul 22, 2010 at 2:21 PM, Noufal Ibrahim <[email protected]> wrote:
> Anand Balachandran Pillai <[email protected]> writes:
>
> [...]
>
>> Can we have it on 30th or 31st then ? ?Personally I prefer
>> next week-end since I am a bit busy this week-end.
>>
>> Noufal ?
>
> [...]
>
> 31st is fine by me. Anyone else?
>
> --
> _______________________________________________
> BangPypers mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/bangpypers
>
------------------------------
Message: 4
Date: Thu, 22 Jul 2010 19:00:43 +0530
From: steve <[email protected]>
To: [email protected]
Subject: Re: [BangPypers] list problem
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hi,
On 07/22/2010 05:02 PM, Anand Balachandran Pillai wrote:
> On Thu, Jul 22, 2010 at 3:21 PM, Vikram<[email protected]> wrote:
>
>> Suppose you have the following list:
>>
>> >>> x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]]
>>
>> My problem is that i wish to obtain the following two dictionaries:
>> xdictstart = {'cat':10, 'dog':1}
>> xdictend = {'cat':30, 'dog':5}
>
>
>> Any nice way to do the above? Thanks.
>>
>>
> Yes. Try this.
>
>>>> x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]]
>>>> x.sort()
>>>> xdictstart = dict(reversed(x))
>>>> xdictend = dict(x)
>>>> xdictstart,xdictend
> ({'dog': 1, 'cat': 10}, {'dog': 5, 'cat': 30})
Are you sure that'll work ? Is creating a dict from a sequence guaranteed to be
executed serially withing the sequence ?
cheers,
- steve
--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
------------------------------
Message: 5
Date: 22 Jul 2010 13:39:13 -0000
From: "Vikram " <[email protected]>
To: <[email protected]>
Subject: Re: [BangPypers] list problem
Message-ID:
<1279794254.s.9697.14894.f.h.tk5hdmluiethynjhafjloibbqmfuz1b5cgvyc10gbglzdcbwcm9ibgvt.f6-145-157.old.1279805953.4...@webmail.rediffmail.com>
Content-Type: text/plain; charset="UTF-8"
many thanks for this to naveen and others who responded.
On Thu, 22 Jul 2010 15:54:14 +0530 wrote
>I suggest that in such cases, avoid the temptation to do something
clever. If it was difficult for you to write the code, it will be even
more difficult to read and understand it.
Unless there is a very good reason, write the simplest, most braindead code.
xdictstart={}
xdictend={}
for item in sorted(x):
xdictend[item[0]] = item[1]
if not item[0] in xdictstart
xdictstart[item[0]] = item[1]
On Thu, Jul 22, 2010 at 3:21 PM, Vikram wrote:
> Suppose you have the following list:
>
>>>> x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]]
>
> My problem is that i wish to obtain the following two dictionaries:
> xdictstart = {'cat':10, 'dog':1}
> xdictend = {'cat':30, 'dog':5}
>
> Any nice way to do the above? Thanks.
>
> -------
> Those interested in the above problem may consider the following code (which
>does not actually do what i want):
>
>>>> xdictend = dict(x)
>>>> xdictend
> {'dog': 3, 'cat': 30}
>
>>>> x
> [['cat', 10], ['cat', 20], ['cat', 30], ['dog', 5], ['dog', 1], ['dog', 3]]
>>>> xdictstart = {}
>>>> map(xdictstart.setdefault, *zip(*x))
> [10, 10, 10, 5, 5, 5]
>>>> xdictstart
> {'dog': 5, 'cat': 10}
>
> _______________________________________________
> BangPypers mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/bangpypers
>
_______________________________________________
BangPypers mailing list
[email protected]
http://mail.python.org/mailman/listinfo/bangpypers
------------------------------
Message: 6
Date: Thu, 22 Jul 2010 19:30:54 +0530
From: Shashwat Anand <[email protected]>
To: Bangalore Python Users Group - India <[email protected]>
Subject: Re: [BangPypers] list problem
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On Thu, Jul 22, 2010 at 3:21 PM, Vikram <[email protected]> wrote:
> Suppose you have the following list:
>
> >>> x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]]
>
> My problem is that i wish to obtain the following two dictionaries:
> xdictstart = {'cat':10, 'dog':1}
> xdictend = {'cat':30, 'dog':5}
>
> Any nice way to do the above? Thanks.
>
How about this :
>>> x
[['cat', 10], ['cat', 20], ['cat', 30], ['dog', 5], ['dog', 1], ['dog', 3]]
Remove duplicates for key pair of dictionary.
>>> keys = list(set(i[0] for i in x))
>>> keys
['dog', 'cat']
Now for every unique keys make a list containing all the items for that
key.
>>> [sorted([i for i in x if i[0]==k], key=operator.itemgetter(1)) for k in
keys]
[[['dog', 1], ['dog', 3], ['dog', 5]], [['cat', 10], ['cat', 20], ['cat',
30]]]
You can now easily create dictionary.
>>> xdictstart = dict(i[0] for i in [sorted([i for i in x if i[0]==k],
key=operator.itemgetter(1)) for k in keys])
>>> xdictstart
{'dog': 1, 'cat': 10}
>>> xdictend = dict(i[-1] for i in [sorted([i for i in x if i[0]==k],
key=operator.itemgetter(1)) for k in keys])
>>> xdictend
{'dog': 5, 'cat': 30}
The benefit is you can make a complete dictionary if you want, not only
start and end values.
> -------
> Those interested in the above problem may consider the following code
> (which does not actually do what i want):
>
> >>> xdictend = dict(x)
> >>> xdictend
> {'dog': 3, 'cat': 30}
>
> >>> x
> [['cat', 10], ['cat', 20], ['cat', 30], ['dog', 5], ['dog', 1], ['dog', 3]]
> >>> xdictstart = {}
> >>> map(xdictstart.setdefault, *zip(*x))
> [10, 10, 10, 5, 5, 5]
> >>> xdictstart
> {'dog': 5, 'cat': 10}
>
> _______________________________________________
> BangPypers mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/bangpypers
>
--
~l0nwlf
------------------------------
Message: 7
Date: Thu, 22 Jul 2010 19:31:54 +0530
From: Shashwat Anand <[email protected]>
To: Bangalore Python Users Group - India <[email protected]>
Subject: Re: [BangPypers] list problem
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On Thu, Jul 22, 2010 at 7:00 PM, steve <[email protected]> wrote:
> Hi,
>
>
> On 07/22/2010 05:02 PM, Anand Balachandran Pillai wrote:
>
>> On Thu, Jul 22, 2010 at 3:21 PM, Vikram<[email protected]> wrote:
>>
>> Suppose you have the following list:
>>>
>>> >>> x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]]
>>>
>>> My problem is that i wish to obtain the following two dictionaries:
>>> xdictstart = {'cat':10, 'dog':1}
>>> xdictend = {'cat':30, 'dog':5}
>>>
>>
>>
>> Any nice way to do the above? Thanks.
>>>
>>>
>>> Yes. Try this.
>>
>> x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]]
>>>>> x.sort()
>>>>> xdictstart = dict(reversed(x))
>>>>> xdictend = dict(x)
>>>>> xdictstart,xdictend
>>>>>
>>>> ({'dog': 1, 'cat': 10}, {'dog': 5, 'cat': 30})
>>
>
> Are you sure that'll work ? Is creating a dict from a sequence guaranteed
> to be executed serially withing the sequence ?
It is nowhere mentioned in Docs IIRC but I have never seen any counter
example.
>
>
> cheers,
> - steve
> --
> random spiel: http://lonetwin.net/
> what i'm stumbling into: http://lonetwin.stumbleupon.com/
> _______________________________________________
> BangPypers mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/bangpypers
>
--
~l0nwlf
------------------------------
_______________________________________________
BangPypers mailing list
[email protected]
http://mail.python.org/mailman/listinfo/bangpypers
End of BangPypers Digest, Vol 35, Issue 21
******************************************
_______________________________________________
BangPypers mailing list
[email protected]
http://mail.python.org/mailman/listinfo/bangpypers