Lots of good answers.
Warning: *this answer is ultra simplistic one to explain the implementation
succinctly*.
A little more from an implementation perspective dict operations usually
involve converting a dict into a hash. This hash is then converted into a
bucket. And sometimes when one gets int
On Thu, Aug 19, 2010 at 10:26 AM, Dipo Elegbede wrote:
> Hi All,
> There really shouldn't be so much debate on the question asked.
> Someone actually gave a direct and clear answer. I'm new at python and
> his explanations were quite understandable.
>
I'm sorry that you sensed a debate in what ha
Here is a small script to sort the dictionary based on key/choice
a = {"key3": 5 , "key2": 8, "key1": 2}
b = {"key2": 7 , "key1": 4, "key3": 9}
c = {"key1": 6 , "key3": 1, "key2": 1}
undecorated = [a, b, c] # how do you sort this list?
sort_on = "key3"
decorated = [(dict_[sort_on], dict_) for dic
Hi All,
There really shouldn't be so much debate on the question asked.
Someone actually gave a direct and clear answer. I'm new at python and
his explanations were quite understandable.
As far as dictionaries are concerned, when you retrieve keys, there is
no guarantee of a particular order.
If yo
Thanks a Ton to all. I got a mucher deeper insight than my question deserved!!!
Thanks once again
anand
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers
On Thu, Aug 19, 2010 at 10:31 AM, Sahasranaman MS wrote:
> On Thursday 19 August 2010 07:08 AM, Kenneth Gonsalves wrote:
>
>> On Wed, 2010-08-18 at 10:28 -0700, Anand Shankar wrote:
>>
>>> I have no clues. Any inputs??
>>>
>> sort order of dictionary keys is not guaranteed. Only a list will retu
On Thu, Aug 19, 2010 at 10:31 AM, Sahasranaman MS wrote:
> On Thursday 19 August 2010 07:08 AM, Kenneth Gonsalves wrote:
>
>> On Wed, 2010-08-18 at 10:28 -0700, Anand Shankar wrote:
>>
>>> I have no clues. Any inputs??
>>>
>> sort order of dictionary keys is not guaranteed. Only a list will retu
On Thursday 19 August 2010 07:08 AM, Kenneth Gonsalves wrote:
On Wed, 2010-08-18 at 10:28 -0700, Anand Shankar wrote:
I have no clues. Any inputs??
sort order of dictionary keys is not guaranteed. Only a list will return
items in the same order as entered.
Python has an OrderedDict class from
On Wed, Aug 18, 2010 at 10:58 PM, Anand Shankar wrote:
> During a tutorial python session with my colleagues I was presented with a
> basic
> question
>
> >>> d = {'apple':2,'banana':5, 'coke': 6}
> >>> print d.keys()
> ['coke', 'apple', 'banana']
>
>
> Question is why does it not return
>
> ['app
On Wed, 2010-08-18 at 10:28 -0700, Anand Shankar wrote:
> I have no clues. Any inputs??
sort order of dictionary keys is not guaranteed. Only a list will return
items in the same order as entered.
--
regards
Kenneth Gonsalves
___
BangPypers mailing lis
Excellent responses so far.
Dictionaries are optimized for retrieving key/value pairs. And to achieve
that, it compromises on the order in which stuff is stored.
This and more is very nicely presented in the Pycon 2010 talk - The Mighty
Dictionary. Highly recommended.
http://us.pycon.org/2010/co
On 18 August 2010 22:58, Anand Shankar wrote:
> During a tutorial python session with my colleagues I was presented with a
> basic
> question
>
d = {'apple':2,'banana':5, 'coke': 6}
print d.keys()
> ['coke', 'apple', 'banana']
>
>
> Question is why does it not return
>
> ['apple','banan
On Wed, Aug 18, 2010 at 10:58 PM, Anand Shankar wrote:
> During a tutorial python session with my colleagues I was presented with a
> basic
> question
>
d = {'apple':2,'banana':5, 'coke': 6}
print d.keys()
> ['coke', 'apple', 'banana']
>
>
> Question is why does it not return
>
> ['appl
During a tutorial python session with my colleagues I was presented with a
basic
question
>>> d = {'apple':2,'banana':5, 'coke': 6}
>>> print d.keys()
['coke', 'apple', 'banana']
Question is why does it not return
['apple','banana','coke']
Similarly:
>>> d = {'a':2,'b':4,'c':5,'d':4,'e':3}
14 matches
Mail list logo