[Python] How to iterate through a list of lists and access each element in the sublist and...

Discussão em 'Python' iniciado por Stack, Maio 16, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working in Python and I'm trying to generate coordinates for circles with their radii being appended after coordinate generation. Once I have the list I want to check it against itself to see if any of the circles will overlap each other, and if so remove one of them. Below is what I have so far and I haven't found a way to iterate through to do what I need.

    import random
    import math
    def circ(x, y):
    return[x, y]
    list = []
    rad = 1
    for i in range(3):
    list.append(circ(random.uniform(rad, 10-rad), random.uniform(rad, 10-rad)))
    print(list)

    for x in list:
    x.append(rad)
    print(x)
    print(list)
    ## Append list of lists with radius so each entry is x, y, r!

    def checker(x, y, r, i, j, k):
    distance = math.sqrt((i-x)**2 + (j-y)**2)
    avgDiam = (.5*(r+k))
    return distance, avgDiam

    Continue reading...

Compartilhe esta Página