Python

I have this disgusting, 3 dimensional list. What dark spells do I need to type in so that the one dimensional list components with a number greater than 7 in their first place are removed, giving me the desired list

Beware Cat Shirt $21.68

Rise, Grind, Banana Find Shirt $21.68

Beware Cat Shirt $21.68

  1. 2 years ago
    Anonymous

    Silly anon
    Access the index of each list's first member using pointer arithmetic and if value >= 7 then pop the whole member

    • 2 years ago
      Anonymous

      I need a concise mechanism that would do the same for lists of many elements, not just the particular list I mentioned in the post.

    • 2 years ago
      Anonymous

      list[l[0]<=7 for l in list]

      do your own homework moron

  2. 2 years ago
    Anonymous

    list[l[0]<=7 for l in list]

    • 2 years ago
      Anonymous

      list comprehension could work like mentioned

      i like numpy because it's specifically designed for 2+ dimensional arrays. you can do vectorized operations which are much faster than list comprehension.

  3. 2 years ago
    Anonymous

    You need to learn K&R or ANSI C.
    Then you'll solve your problem.

  4. 2 years ago
    Anonymous

    Try performing cross-dimensional matrix multiplication on the particular value that you want to remove.

  5. 2 years ago
    Anonymous

    go through number in 1st list in 1st list in 1st list
    go through number in 2nd list in 1st list in 1st list
    etc.
    >muh big O
    your butthole looks like a big O

  6. 2 years ago
    Anonymous

    use recursion

  7. 2 years ago
    Anonymous

    This is indeed very disgusting.
    It would look so much nicer with tuples.

  8. 2 years ago
    Anonymous

    [...]

    >homework thread
    this board is 18+

    • 2 years ago
      Anonymous

      I..don't have any hw. Ugh this was a waste of time

      • 2 years ago
        Anonymous

        >Ugh this was a waste of time
        >Ugh
        And now you "ugh" and "sigh" like a redditor.

        Yes this was a "waste" of OUR time. The sticky post says this is NO tech support board. Ask reddit for help not here.

        • 2 years ago
          Anonymous

          What's wrong about reddit? Lists are just so confusing I had to ask somewhere.

      • 2 years ago
        Anonymous

        frick off dumbphone poster, there are literally 100 online pyhon interpreters that work from just a browser. not our fault you are shtoopid.

      • 2 years ago
        Anonymous

        Then why do you need it so urgently and spoon-fed?

  9. 2 years ago
    Anonymous

    map a lambda function over the list

  10. 2 years ago
    Anonymous

    Hire me!
    #!/usr/bin/env python3

    x=[[[1,2]], [[3,4], [5,6]], [[7,8], [9,10], [11,12]]]

    for i in reversed(range(0, len(x*~~:
    for j in x[i]:
    for el in j:
    if j[0] > 7:
    j.pop()
    while True:
    if len(j) == 0:
    break
    if j[-1] < 8:
    break
    j.pop()
    _x=[]
    for k in x[i]:
    if len(k) > 0:
    _x.append(k)
    x[i] = _x
    print(x)

    [[[1, 2]], [[3, 4], [5, 6]], [[7, 8]]]

    • 2 years ago
      Anonymous

      Does it have to be this big? I was expecting it to only take
      2-3 lines

      • 2 years ago
        Anonymous

        >Does it have to be this big?
        No

        • 2 years ago
          Anonymous

          >No
          Prove it.

          • 2 years ago
            Anonymous

            >Prove it.
            Proved in

            >I was expecting it to only take
            >2-3 lines
            Only one line needed provided you use list comprehensions:
            y = [[x2 for x2 in x1 if x2[0] <= 7] for x1 in x]
            You can do something similar with numpy, but the syntax is different.

      • 2 years ago
        Anonymous

        >I was expecting it to only take
        >2-3 lines
        Only one line needed provided you use list comprehensions:
        y = [[x2 for x2 in x1 if x2[0] <= 7] for x1 in x]
        You can do something similar with numpy, but the syntax is different.

        • 2 years ago
          Anonymous

          Finally..

          • 2 years ago
            Anonymous

            finally what? ungrateful shit

    • 2 years ago
      Anonymous

      Holy frick anon that is hideous, have you ever heard of list comprehensions? Or functional programming?

  11. 2 years ago
    Anonymous

    >not using a single list to store elements in a 3 dimensional space
    Kek

Your email address will not be published. Required fields are marked *