a question on the new dict() keyword argument syntax

Discussion in 'Python' started by Oktay Safak, Aug 2, 2003.

  1. Oktay Safak

    Oktay Safak Guest

    Hi,

    Is there an equivalent keyword argument syntax for these cases:

    d1 = {1:"one"}

    d2 = {"1":"one"}

    these don't work, of course:

    >>> a = dict(1 = "one")

    SyntaxError: keyword can't be an expression

    >>> a = dict("1" = "one")

    SyntaxError: keyword can't be an expression

    Just curious...
     
    Oktay Safak, Aug 2, 2003
    #1
    1. Advertisements

  2. "Oktay Safak" <> wrote in message
    news:...
    > Hi,
    >
    > Is there an equivalent keyword argument syntax for these cases:
    >
    > d1 = {1:"one"}
    >
    > d2 = {"1":"one"}
    >
    > these don't work, of course:
    >
    > >>> a = dict(1 = "one")

    > SyntaxError: keyword can't be an expression
    >
    > >>> a = dict("1" = "one")

    > SyntaxError: keyword can't be an expression


    As you discovered, there is no equivalent. The new
    syntax is limited to strings that are valid identifiers
    (variable names).


    Raymond Hettinger
     
    Raymond Hettinger, Aug 2, 2003
    #2
    1. Advertisements

  3. Oktay Safak

    Oktay Safak Guest

    > > Hi,
    > >
    > > Is there an equivalent keyword argument syntax for these cases:
    > >
    > > d1 = {1:"one"}
    > >
    > > d2 = {"1":"one"}
    > >
    > > these don't work, of course:
    > >
    > > >>> a = dict(1 = "one")

    > > SyntaxError: keyword can't be an expression
    > >
    > > >>> a = dict("1" = "one")

    > > SyntaxError: keyword can't be an expression

    >
    > As you discovered, there is no equivalent. The new
    > syntax is limited to strings that are valid identifiers
    > (variable names).
    >
    >
    > Raymond Hettinger


    Thanks :)
     
    Oktay Safak, Aug 2, 2003
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexander Kozlovsky

    dict!ident as equivalent of dict["ident"]

    Alexander Kozlovsky, May 21, 2006, in forum: Python
    Replies:
    5
    Views:
    594
    Alexander Kozlovsky
    May 22, 2006
  2. Paul Melis

    dict.has_key(x) versus 'x in dict'

    Paul Melis, Dec 6, 2006, in forum: Python
    Replies:
    48
    Views:
    1,615
    Kent Johnson
    Dec 15, 2006
  3. Almad
    Replies:
    8
    Views:
    607
    Terry Reedy
    Dec 14, 2006
  4. Drew
    Replies:
    19
    Views:
    1,612
    Duncan Booth
    Mar 15, 2007
  5. Kai Kuehne
    Replies:
    4
    Views:
    539
    Stargaming
    Jul 26, 2007
  6. Beni Cherniavsky

    Special keyword argument lambda syntax

    Beni Cherniavsky, Mar 13, 2009, in forum: Python
    Replies:
    1
    Views:
    477
    Beni Cherniavsky
    Mar 14, 2009
  7. Albert van der Horst

    dict's as dict's key.

    Albert van der Horst, Jan 13, 2010, in forum: Python
    Replies:
    5
    Views:
    468
    Lie Ryan
    Jan 17, 2010
  8. gabriele renzi
    Replies:
    12
    Views:
    245
    Yukihiro Matsumoto
    Nov 19, 2003
Loading...