samedi 23 avril 2022

Pop into another list with list comprehension

I wrote this section of code to be used in a bigger code to simulate a zombie apocalypse. I have a class to represent healthy people and then zombies. The block of code here was written to make a list of healthy people and one zombie and assign them random positions, but I see now that I didn't include the combos list into the list comprehension loop to allow for random assignment. Is there a way I can include that in? I did not include my classes library only so this question wasn't obnoxiously long. Thanks!

combos = list(product(range(sysvals.A), range(sysvals.B)))
r.shuffle(combos)
temp = combos.pop()
row = temp[0]
col = temp[1]
populace = [zc.Human(i,row,col,'Alive') if i != 0 else zc.Zombie(i,row,col,'Alive') for i in 
range(sysvals.N)]



Aucun commentaire:

Enregistrer un commentaire