0

Python list

lets say i have a list with coordinates: [(1,1), (2,2), (3,3)] and lets say that the first coordinates in the list (1,1), change to (5,5) for example, how would i change (2, 2) to (1,1) and (3,3) to (2,2) so basically each coordinates except the first one change to the place of where the coordinates in front of them used to be? so now the list would be [(5,5), (1,1), (2,2)]

28th Jul 2021, 9:56 AM
Kirill
Kirill - avatar
10 Réponses
+ 6
a=[(1, 1), (2, 2), (3, 3) ] a.pop() a.insert(0,(5, 5))
28th Jul 2021, 10:02 AM
Abhay
Abhay - avatar
+ 6
Oma Falk , list.push() is not yet implemented in python 🙂
28th Jul 2021, 11:00 AM
Lothar
Lothar - avatar
+ 5
coords = [(5,5)]+coords[1:]
28th Jul 2021, 10:03 AM
Oma Falk
Oma Falk - avatar
+ 4
Kirill Vidov , it was a joke from me addressed for Oma Falk, it does not need to be implemented, because list has: list.append(), list.extend() and list.insert().
28th Jul 2021, 12:03 PM
Lothar
Lothar - avatar
+ 2
Oma Falk what if we don't know how much coordinates are in the list?
28th Jul 2021, 10:00 AM
Kirill
Kirill - avatar
+ 2
Lothar uuuuuups😉 Maybe queue has it.
28th Jul 2021, 12:25 PM
Oma Falk
Oma Falk - avatar
+ 1
coords = [(0,0),(1,1),(2,2)] coords.push((5,5)) coords.pop(0)
28th Jul 2021, 9:59 AM
Oma Falk
Oma Falk - avatar
+ 1
Abhay Oma Falk thank you
28th Jul 2021, 10:09 AM
Kirill
Kirill - avatar
+ 1
Lothar do you know when will they implement it?
28th Jul 2021, 11:04 AM
Kirill
Kirill - avatar
0
I think coords = [(5, 5)] + coords[:-1]
30th Jul 2021, 5:39 AM
Zokir Zokir
Zokir Zokir - avatar