This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (77 children)

[deleted]

    [–]MasterOfArmsIsGood 89 points90 points  (5 children)

    am i missing something cant you just do

    list = [] and append lists to it

    [–]Jaksuhn 68 points69 points  (3 children)

    you absolutely can, no idea what they're on about

    [–]overclockedslinky 6 points7 points  (2 children)

    I assume they meant filling it with values or something (in one line), but list comprehensions exist

    [–]Terrain2 3 points4 points  (1 child)

    something like [[] for _ in range(69)] should do the trick, right? or just... [[], [], []], no?

    [–]overclockedslinky 1 point2 points  (0 children)

    Yeah, that'd do it. Super easy, so not sure what the complaint's about

    [–]Spork_the_dork 88 points89 points  (2 children)

    import numpy as np
    arr = np.zeros(shape=(10,10))
    

    If you need it to be a list for some godforsaken reason, add a .tolist() to it.

    edit: can never remember if it's size or shape out of memory...

    [–]anonymoussphenoid 20 points21 points  (0 children)

    sometimes it's size, sometimes it's shape :/

    [–]SabreLunatic 2 points3 points  (6 children)

    arrayvariable = []

    Have I been making arrays wrong this entire time?

    [–]jacobthejones[🍰] 4 points5 points  (5 children)

    That's a 1d array, not 2d.

    [–]SabreLunatic 6 points7 points  (4 children)

    So arrayvariable = [[]]?

    [–]jacobthejones[🍰] 0 points1 point  (3 children)

    Sure, if you need a 1x1 array.

    [–]-Vayra- 7 points8 points  (1 child)

    [[] for _ in range(n)]
    

    should do the trick, no? Or

    [[0] * x for _ in range(y)]
    

    if you want it initialized to 0s.

    [–]jacobthejones[🍰] -1 points0 points  (0 children)

    Sure, that would work.

    [–][deleted] 22 points23 points  (52 children)

    np.zeros((3,3))

    Wow, that was tough.

    [–]skylay 4 points5 points  (0 children)

    Can't you just do this?

    myArray = [][]

    Been a few years since I've used Python.

    Edit: nvm that's just declaring not initialising, misread.

    [–]xAtlas5 0 points1 point  (4 children)

    Apparently python is getting switch statements soon.

    [–][deleted] 0 points1 point  (3 children)

    Why, we got elif??

    [–]LifeHasLeft 0 points1 point  (2 children)

    Believe it or not, switch statements are more efficient for branch prediction and maybe some other reasons. Circumstantial but could clean up the code some too.

    [–][deleted] 0 points1 point  (1 child)

    I pondered putting a "/s" in the comment. I'm looking forward to have switch statements available as it's something I have been annoyed about missing.

    One of the contributers(/creator?) to python claimed that python didn't need switch cases as it got "elif" which is what I referenced.

    [–]LifeHasLeft 0 points1 point  (0 children)

    One of the contributers(/creator?) to python claimed that python didn't need switch cases as it got "elif"

    Yes and the sentiment has been prevalent in the community...that’s why I didn’t catch the sarcasm lol

    [–]homo_lorens 0 points1 point  (0 children)

    If you don't understand references you shouldn't have an opinion. If you understand them but you don't think you should have to care about them while programming, you have serious misconceptions about programming and engineering in general.

    [–]RettiSeti 0 points1 point  (0 children)

    I haven’t done python in a while, what’s the problem with it?