[Tutor] making a random list, then naming it

eryksun eryksun at gmail.com
Sat May 25 03:51:19 CEST 2013


On Fri, May 24, 2013 at 9:10 PM, Dave Angel <davea at davea.name> wrote:
>
> Is lists[(3,8)]  really so much harder to type than
>     list_3_8  ?

Since a comma creates a tuple, in this context you can just use
lists[3,8] to save a couple more keystrokes.

    >>> from random import Random
    >>> randint = Random(42).randint

    >>> lists = {}
    >>> lists[3,8] = [randint(0,8) for i in range(3)]
    >>> lists
    {(3, 8): [1, 0, 4]}


More information about the Tutor mailing list