2-dimensional lists - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

2-dimensional lists

LEN44LEN44 Posts: 1Member
I'm somewhat of a newb to Python and I don't know how to make 2D lists. Could anyone help me?

Comments

  • bubbatremellbubbatremell Posts: 39Member
    There's a number of ways to do it. The key to all of them is remembering that lists can hold anything. So,
    e = [[] for x in range(10)]
    #generates a list with 10 other lists in it, so you can do stuff like
    e[0]
    >>>[]
    len(e)
    >>>10
    len(e[4])
    >>>0

    I suppose you could build it manually, or with a loop, if you like.
    e = []
    for x in range(10):
    e.append([])

Sign In or Register to comment.