retrieve key of only element in a dictionary (Python 3)

Gene Heskett gheskett at wdtv.com
Sat Mar 19 09:23:31 EDT 2016


On Saturday 19 March 2016 04:42:29 Chris Angelico wrote:

> On Sat, Mar 19, 2016 at 7:29 PM, Steven D'Aprano <steve at pearwood.info> 
wrote:
> > On Sat, 19 Mar 2016 12:36 pm, Chris Angelico wrote:
> >> So unpacking will give you those keys - in an arbitrary order. Of
> >> course, you don't care about the order when there's only one.
> >
> > But what if you want the key in reverse order?
> >
> > # Standard order
> > [key] = mydict
> >
> > # Reverse order
> > [yɘʞ] = mydict
>
> Unfortunately, Steven, that won't work - you forgot to invert the
> brackets. And no, switching them won't work:
>
> ]yɘʞ[ = mydict
>
> You need to have actual backward brackets so Python knows you want to
> iterate backward through the dictionary, starting with the last value
> and proceeding to the first index.
>
> ChrisA

And my obvious question is, does python have such a construction 
as ]var[ ?

Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page <http://geneslinuxbox.net:6309/gene>



More information about the Python-list mailing list