I'm building a Formula1 race simulator in python and I'm trying to make a overtake function, basically, i've all the drivers stored in a list and once one of the drivers surpasses the other I need to invert their position in the list
['hamilton','vertsappen','perez','sainz']
['hamilton','perez','verstappen','sainz']
is there any way to do so?
since now I have tried to store the original positions in a temporary variable but I keep finding myself with duplicates in the list
original temporary variables
overtaken temp = Valteri Bottas
overtaker temp = Nicholas Latifi
after the inverting
overtaken temp = Valteri Bottas
overtaker temp = Valteri Bottas