Python Forum

Full Version: Why isn't this code working ? (noob here)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
It should output the list with the dictionary with the changed values as specified in the second for loop, but it doesnt. Picture of output is included.


 aliens = []
for l in range (1,30):
    alien_specs = {'speed':'high' , 'color':'blue' , 'points': 5 }
    aliens.append(alien_specs)

for pi in aliens[:2]:
    if alien_specs['points'] == 5:
        alien_specs['speed'] = 'low'
        alien_specs['color'] = 'red'

for j in aliens[:5]:
    print(j)

print('.............................................')
Im using python 3
for pi in aliens[:2]:
    if pi['points'] == 5:
        pi['speed'] = 'low'
        pi['color'] = 'red'