0
Appropriate/optimal way to Append an item to the Left of an array
Can someone examine my code, it's working the way I want it too, I just would like someone experienced to let me know if it would actually be usable or if I'm ignorant and there is a significantly better way to do it(which I'm sure there is) Also, I tried modifying the perm variable, but when I tried to use it in the next for loop, it seemed like maybe it was a one time use item.... But maybe I'm ignorant on that too. https://sololearn.com/compiler-playground/c38YXM0onQP1/?ref=app
2 Réponses
+ 1
Robert Atkins
what is the purpose of using deque? just construct your list directly.
from itertools import permutations
home = {"lat": 1, "long": 1}
places = [ {"lat": 55.8642, "long": -4.2518}, {"lat": 52.4862, "long": -1.8904}, {"lat": 53.2268, "long": -0.5379}, {"lat": 53.5229, "long": -1.1312} ]
routes = [[home, *i] for i in permutations(places)]
for i,v in enumerate(routes):
print(f"perm {i}: {v}")
#or if you want fancy printing:
'''
for i,v in enumerate(routes):
print(f"perm {i}:\n{'lat':^10}{'long':^10}")
print(*(f' {p["lat"]:7.4f} | {p["long"]:7.4f} \n' for p in v),sep='')
'''
+ 1
Bob_Li thank you