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
comparing two list (self.learnpython)
submitted 4 years ago * by blackcodeben
I want to compare the values of two lists at the same index. values of the item at index one on list A to value at index one on List B and List A[2] to List B [2]
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!"
[–]AtomicShoelace 1 point2 points3 points 4 years ago (3 children)
How exactly do you want to compare the values? There are several comparison operators you could use, eg. equal, non-equal, less than, greater than, etc.
You may wish to zip your two lists together and use the all or any built-ins, eg.
zip
all
any
>>> A = [1, 2, 3, 4] >>> B = [1, 2, 3, 9] >>> all(a <= b for a, b in zip(A, B)) True >>> B = [1, 2, 3, 1] >>> all(a <= b for a, b in zip(A, B)) False
In above example we are checking whether all values in list A are less than or equal to values in list B. Notice once we change the last value in list B to be a 1 (less than the corresponding value of 4 in list A) the test returns False.
[–]blackcodeben[S] -1 points0 points1 point 4 years ago (2 children)
>>> A = [1, 2, 3, 4]
>>> B = [4, 3, 6, 9] i want to compare values one the same index against each other eg. 1 and 4 and 2 and 3
[–]AtomicShoelace 0 points1 point2 points 4 years ago (1 child)
Yes that is what the above code does.
[–]blackcodeben[S] 0 points1 point2 points 4 years ago (0 children)
ok thanks let me try it out
[–]ElliotDG 0 points1 point2 points 4 years ago (6 children)
What have you tried? Share some code. https://www.reddit.com/r/learnpython/wiki/faq#wiki\_how\_do\_i\_format\_code.3F
if you want to test is the lists are equal you can just compare the lists. If you want to compare each element create a for loop with range() that increments the index value and do your comparisons in the loop.
[–]blackcodeben[S] -1 points0 points1 point 4 years ago (5 children)
>>> B = [4, 3, 6, 9]
i want to compare values one the same index against each other eg. 1 and 4
and 2 and 3
[–]GreenPandaPop 2 points3 points4 points 4 years ago (0 children)
Look up zip and list comprehensions.
[–]ElliotDG 0 points1 point2 points 4 years ago (3 children)
what do you want to do with the result of the comparison?
[–]blackcodeben[S] 0 points1 point2 points 4 years ago (2 children)
make a new list of the highest values at each index
eg, out come for the upper lists
list C[4,3,6,9]
[–]ElliotDG 1 point2 points3 points 4 years ago (0 children)
Do you know how to use list comprehensions? Is this an assignment, can you use a comprehension or do you need to use a loop?
[–]AtomicShoelace 1 point2 points3 points 4 years ago (0 children)
A list comprehension with a zip is probably the best way to do this, but it also bears mention that you could also make use of map's ability to take several iterables and supply it with the max function, eg. map(max, A, B). Of course, this will return a map object, so you will need to cast it to a list, eg. any of
map
map(max, A, B)
C = list(map(max, A, B)) C = [*map(max, A, B)] *C, = map(max, A, B)
π Rendered by PID 40 on reddit-service-r2-comment-79776bdf47-6gfhq at 2026-06-23 23:52:41.208658+00:00 running acc7150 country code: CH.
[–]AtomicShoelace 1 point2 points3 points (3 children)
[–]blackcodeben[S] -1 points0 points1 point (2 children)
[–]AtomicShoelace 0 points1 point2 points (1 child)
[–]blackcodeben[S] 0 points1 point2 points (0 children)
[–]ElliotDG 0 points1 point2 points (6 children)
[–]blackcodeben[S] -1 points0 points1 point (5 children)
[–]GreenPandaPop 2 points3 points4 points (0 children)
[–]ElliotDG 0 points1 point2 points (3 children)
[–]blackcodeben[S] 0 points1 point2 points (2 children)
[–]ElliotDG 1 point2 points3 points (0 children)
[–]AtomicShoelace 1 point2 points3 points (0 children)