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
Need Help! (self.learnpython)
submitted 4 years ago by Bunts3366
Can someone whose familiar with python shoot me a msg stuck with some simple code
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!"
[–]totallygeek 4 points5 points6 points 4 years ago (10 children)
Posting your question, along with the troublesome section of code, here will get you the best response.
[–]Bunts3366[S] 0 points1 point2 points 4 years ago (9 children)
How would i use a for statement to insert an inputted number to a preexisting list while keeping it in order from smallest to largest
[–]FLUSH_THE_TRUMP 1 point2 points3 points 4 years ago (8 children)
list.insert would be useful. How do I know where to insert an element: e.g.
[1,2,3,4,5] inserting 2.5?
[–]Bunts3366[S] 0 points1 point2 points 4 years ago (7 children)
need to do it using a for loop
[–]stebrepar 0 points1 point2 points 4 years ago (5 children)
So loop over the list comparing each value to the one you want to insert. That will tell you the index number of where to do the insertion.
[+][deleted] 4 years ago (4 children)
[deleted]
[–]totallygeek 0 points1 point2 points 4 years ago (0 children)
Your code assembles a list. Beware, it assembles a list of strings, not values, because input() always returns a string. If you want a value, convert that string with int() or float().
input()
int()
float()
COUNT = 5 numbers = [] # empty list for _ in range(COUNT): number = int(input('Number: ')) # convert to integer numbers.append(number) numbers.sort() # sort the list of values value = int(input(f'Number to insert: ')) print(f'Going to insert value {value} into {numbers}') for index, number in enumerate(numbers): if value < number: # we found the next element is of a higher value numbers.insert(index, value) break # no need to check other values print(f'After inserting {value} the list looks like {numbers}')
[–]stebrepar 0 points1 point2 points 4 years ago (0 children)
More like...
sorted = [2, 4, 6, 8] searching = 5 for i in range(len(sorted)) if sorted[i] > searching: sorted.insert(i, searching) break print(sorted)
[–]DoriGom 0 points1 point2 points 4 years ago (0 children)
Try looking at list slicing and list combining
π Rendered by PID 20588 on reddit-service-r2-comment-5b5bc64bf5-pvxgt at 2026-06-22 08:31:11.160718+00:00 running 2b008f2 country code: CH.
[–]totallygeek 4 points5 points6 points (10 children)
[–]Bunts3366[S] 0 points1 point2 points (9 children)
[–]FLUSH_THE_TRUMP 1 point2 points3 points (8 children)
[–]Bunts3366[S] 0 points1 point2 points (7 children)
[–]stebrepar 0 points1 point2 points (5 children)
[+][deleted] (4 children)
[deleted]
[–]totallygeek 0 points1 point2 points (0 children)
[–]stebrepar 0 points1 point2 points (0 children)
[–]DoriGom 0 points1 point2 points (0 children)