Pythonic list/tuple/dict layout?

Akira Kitada akitada at gmail.com
Sun Jan 25 09:18:28 CET 2009


Hi,

There is more than one way to write a list/tuple/dict in Python,
and actually different styles are used in standard library.
As a hobgoblin of little minds, I rather like to know which style is
considered "Pythonic"
in the community.

I collected common layout from existing code and pasted them below.
My vote would go to d1. How about yours?

If there is consensus on this, that might be worth being included in PEP 8.

Thanks,

"""
d1 = {
    0: "ham",
    1: "jam",
    2: "spam",
    3: "alot",
    4: "knights",
    5: "who",
    6: "say",
    7: "ni",
    8: "dead",
    9: "parrot",
}

d2 = {
    0: "ham",
    1: "jam",
    2: "spam",
    3: "alot",
    4: "knights",
    5: "who",
    6: "say",
    7: "ni",
    8: "dead",
    9: "parrot",}

d3 = {0: "ham",
      1: "jam",
      2: "spam",
      3: "alot",
      4: "knights",
      5: "who",
      6: "say",
      7: "ni",
      8: "dead",
      9: "parrot",
      }

d4 = {0: "ham",
      1: "jam",
      2: "spam",
      3: "alot",
      4: "knights",
      5: "who",
      6: "say",
      7: "ni",
      8: "dead",
      9: "parrot",}

d5 = {0: "ham",
      1: "jam",
      2: "spam",
      3: "alot",
      4: "knights",
      5: "who",
      6: "say",
      7: "ni",
      8: "dead",
      9: "parrot",
}
"""



More information about the Python-list mailing list