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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.