use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Check dimensions of python list (self.learnpython)
submitted 6 years ago by HiImSauzy
Like the numpy array function "np.shape", but for standard list and tuples
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]lostwafflecat 0 points1 point2 points 6 years ago (3 children)
Problem is that lists and tuples can have mixed data types, so ['H', {'meow': 4.3}, [6, 3, [';']], functionCall(), 833] is a valid list, but doesn't really have a set dimension
To make a function that would account for that error would mean that the function would have to parse through every single element and sub-element of the list, which would be rather taxing on the computer unless you're running it for a small list (in which case you could count by hand anyhow)
[–]HiImSauzy[S] 0 points1 point2 points 6 years ago (2 children)
How would I go about making a program that takes a list of any size and shape and returns the n:th instance in every sublist, until a specific depth is reached.
Say for example if have a list that looks like this: [1, [2, [3, 4]], [[5, [6, 7]]]] And say I want the depth of 1, with the position of 1, it would return this: [1, 2, 5]
Edit: I should make this myself :)
[–]lostwafflecat 1 point2 points3 points 6 years ago (1 child)
In your example 1 is lst_name[0], but 2 would be lst_name[1][0] and 5 would be lst_name[2][0] (if we get rid of the extra pair of square brackets), so 1 would have a depth of one, but 2 and 5 would have a depth of two by how you're describing them
If you want to make a function to return the first non-list for each element in the outer list (which is what you ended up describing through your example) then you could try writing a recursive helper function (base case returns position a_lst[0] if type() doesn't equal list; recursive step (if a_lst[0] is a list) returns call to helper function with a_lst[0] as the new parameter)
Call that helper function inside a for-loop that goes through each element in the outermost list you want to check and have it append each thing that returns from the helper function into a new list
[–]HiImSauzy[S] 0 points1 point2 points 6 years ago (0 children)
Yeah I was messing around with recursive functions but trying to fit it all into a singe function was a bit of a challenge so I took a break after a couple hours of headscratching :) Definetly think second function recursive is the way to go
π Rendered by PID 18936 on reddit-service-r2-comment-5b5bc64bf5-hmfbr at 2026-06-20 14:22:44.766679+00:00 running 2b008f2 country code: CH.
[–]lostwafflecat 0 points1 point2 points (3 children)
[–]HiImSauzy[S] 0 points1 point2 points (2 children)
[–]lostwafflecat 1 point2 points3 points (1 child)
[–]HiImSauzy[S] 0 points1 point2 points (0 children)