people = ["James","COP","George","COP","Sam","Mac","Johnny","Karina"]
cops = [(idx+1) for idx, val in enumerate(people) if val == "COP"] #cops' positions
peoplePositions = [(x+1) for x in range(len(people))] #index positions
distances = []
for x in peoplePositions:
for y in cops:
distances.append(abs(x-y))
#the output would be "Johnny"
Hello, guys! I'm working on this question and basically I have a list with some people/objects that is actually a circular table, i.e., its head it is connected to its tail. Now I want to take the distance (of index positions) between the "COPs" and people, then output who got the maximum distance from the "COPs". In case all of them got the same distance, the output must be all of them.
This is my code and in the end I got the distances between all the people and the "COPs". I thought about making a nested loop through the distances with a range of len(peoplePositions) and a range of len(cops), but I had no progress.