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. Advertising

  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. Advertising

  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. Advertising

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. Replies:
    6
    Views:
    468
    Peter Otten
    May 10, 2007
  2. Hamilton, William

    RE: keyword checker - keyword.kwlist

    Hamilton, William, May 10, 2007, in forum: Python
    Replies:
    4
    Views:
    363
  3. Kai Kuehne
    Replies:
    4
    Views:
    390
    Stargaming
    Jul 26, 2007
  4. Beni Cherniavsky

    Special keyword argument lambda syntax

    Beni Cherniavsky, Mar 13, 2009, in forum: Python
    Replies:
    1
    Views:
    325
    Beni Cherniavsky
    Mar 14, 2009
  5. gabriele renzi
    Replies:
    12
    Views:
    177
    Yukihiro Matsumoto
    Nov 19, 2003
Loading...

Share This Page