Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #47570

Re: Reply to post 'Tryign to add a valkue to a set'

From Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com>
Newsgroups comp.lang.python
Subject Re: Reply to post 'Tryign to add a valkue to a set'
Date 2013-06-10 16:58 +0200
Message-ID <856h8a-qec.ln1@satorlaser.homedns.org> (permalink)
References <201306100650.873248273868@forums.devshed.com> <mailman.2963.1370861835.3114.python-list@python.org> <p20h8a-q0c.ln1@satorlaser.homedns.org> <64451427-9f6f-41fb-a437-e1755c9736f7@googlegroups.com>

Show all headers | View raw


Am 10.06.2013 15:37, schrieb Νικόλαος Κούρας:
> Τη Δευτέρα, 10 Ιουνίου 2013 4:14:33 μ.μ. UTC+3, ο χρήστης Ulrich Eckhardt έγραψε:
>> Am 10.06.2013 12:57, schrieb Νικόλαος Κούρας:
>>
>>>>Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich
>>> Eckhardt έγραψε:
>>
>>>
>>
>>> for key in sorted( months.keys() ):
>>
>>>           print('''
>>
>>>                   <option value="%s"> %s </option>
>>
>>>           ''' % (months[key], key) )
>>
>>>
>>
>>> this in fact works, it sorts the dict by its keys()
>>
>>
>>
>> No, it does not sort the dict. Please slow down, relax and take a look
>> at the documentation of sorted(). You are jumping to conclusions based
>> on flawed expectations and assumptions, which can only yield garbage in
>> the end.
>
> it doe ssort the dict at least for keys() why not for values() too?

Well, because it does not sort the dict, it sorts the sequence that you 
pass into sorted(). The dictionary that you retrieved from is not 
modified. Which part of the documentation is unclear to you? Did you 
even bother reading the docs?


> for key in sorted( months.keys() ):
>           print('''
>                   <option value="%s"> %s </option>
>           ''' % (months[key], key) )
>
> this in fact works, it sorts the dict by its keys() was mistaken before
> but the sorting aint correct because its done alphabetically and not by
> integer value.

Listen: Computers will always do what you tell them to. If you tell them 
garbage, they will do garbage. If that is not what you want them to do, 
it's your own fault. That means that you have to precisely(!!!) describe 
what you want when talking to a computer. The computer will not try to 
guess what you might have wanted.

Now, the above claim, that "it sorts the dict by its keys()" is simply 
wrong. Instead, it outputs the dictionary's elements sorted by their 
key. There is a fine distinction between the two. I know what you mean, 
because I'm a human being and I can copy with your vague description, 
but the computer doesn't.

Good luck, I'm outta here....

Uli

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Reply to post 'Tryign to add a valkue to a set' Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2013-06-10 13:57 +0300
  Re: Reply to post 'Tryign to add a valkue to a set' Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-06-10 15:14 +0200
    Re: Reply to post 'Tryign to add a valkue to a set' Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2013-06-10 06:37 -0700
      Re: Reply to post 'Tryign to add a valkue to a set' Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-06-10 16:58 +0200
    Re: Reply to post 'Tryign to add a valkue to a set' Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2013-06-10 07:03 -0700
      Re: Reply to post 'Tryign to add a valkue to a set' Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2013-06-10 07:37 -0700
  Re: Reply to post 'Tryign to add a valkue to a set' russ.pobox@gmail.com - 2013-06-10 08:34 -0700
    Re: Reply to post 'Tryign to add a valkue to a set' Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2013-06-10 08:55 -0700
  Re: Reply to post 'Tryign to add a valkue to a set' russ.pobox@gmail.com - 2013-06-11 00:21 -0700

csiph-web