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

Skip to content
# 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

Silly anon

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

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.

do your own homework retard

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

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.

You need to learn K&R or ANSI C.

Then you'll solve your problem.

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

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 asshole looks like a big O

use recursion

This is indeed very disgusting.

It would look so much nicer with tuples.

>homework thread

this board is 18+

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

>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.

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

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

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

map a lambda function over the list

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]]]

Does it have to be this big? I was expecting it to only take

2-3 lines

>Does it have to be this big?

No

>No

Prove it.

>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.

Finally..

finally what? ungrateful shit

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

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

Kek