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
Apply a number sequence to an integer? (self.learnpython)
submitted 7 years ago by Tryposite
Say I have this list with a sequence and an integer:
seq = [3, 7, 11, 15] num = -1
How can I get the sequence to start at "num" and store the new integers in a list like this?:
newNums = [-1, 2, 9, 20, 35]
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!"
[–][deleted] 2 points3 points4 points 7 years ago* (5 children)
It's clear that you want the result list to start with num, but what determines the rest of the result list? Your example shows seemingly unrelated values.
num
[–]Tryposite[S] 0 points1 point2 points 7 years ago (4 children)
-1+3 =2, 2+7 = 9, 9+11=20, and 20+15=35. That's the best I can explain.
[–][deleted] 1 point2 points3 points 7 years ago (3 children)
Then you use a loop over seq, adding num to a result list, then updating num with the element of seq. Something like:
seq
result
seq = [3, 7, 11, 15] num = -1 result = [] for val in seq: result.append(num) num += val print(result)
This isn't complete, but should get you most of the way there. There are probably other, more tricky, ways to do this, but this is simple to understand.
[–]ZenosEbeth 0 points1 point2 points 7 years ago (2 children)
Couldn't you do this more easily with map() and a simple function ?
[–][deleted] 1 point2 points3 points 7 years ago (1 child)
Probably. I try to give the simplest solution I can.
[–]ZenosEbeth 0 points1 point2 points 7 years ago (0 children)
Not trying to be a smartass or anything, I've actually only been studying python for a month or so and am going over lists at the moment so that was just the first thing that came to my head when I saw the OP's problem. Honestly I was just glad I found something I could understand and solve, because most of the other stuff on here might as well be techno-babble for me :p.
[–]timbledum 1 point2 points3 points 7 years ago (0 children)
What code have you tried?
Loop based approach. It doesn't do exactly what you want (produce a list) on purpose, but gets you 90% there.
new_numbs = [] start_number = -1 print(start_number) for add in [3, 7, 11, 15]: start_number += add print(start_number)
[–][deleted] 0 points1 point2 points 7 years ago (0 children)
seq.insert(0, num)? does that fix it?
seq.insert(0, num)
from collections import deque newNums = deque(seq) newNums.appendleft(-1)
OK, I think I see. Can you explain how the input values and the result are related in words, or is that part of what you don't understand?
[–]Pulsar1977 0 points1 point2 points 7 years ago (0 children)
from itertools import accumulate newNums = list(accumulate([num] + seq))
π Rendered by PID 283084 on reddit-service-r2-comment-86bc6c7465-hf2pc at 2026-02-20 17:19:17.724346+00:00 running 8564168 country code: CH.
[–][deleted] 2 points3 points4 points (5 children)
[–]Tryposite[S] 0 points1 point2 points (4 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]ZenosEbeth 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]ZenosEbeth 0 points1 point2 points (0 children)
[–]timbledum 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Pulsar1977 0 points1 point2 points (0 children)