Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8082

Python • Iterating over pairs of list elements

$
0
0
Hi, everyone.

Code:

# Is there a simpler way of writing the next 4 lines?:for px in range(len(bodies)):    for opx in range(px+1, len(bodies)):        p=bodies[px]        op=bodies[opx]
(I'm working my way through 'Make Games With Python'. This is from Chapter 6, a solar system simulator. I only want to calculate for each pair of 'bodies' once.)

Statistics: Posted by BMardle — Sun Feb 15, 2026 9:56 am



Viewing all articles
Browse latest Browse all 8082

Trending Articles