from random import choice names = ['gobblegorp','andremodes','palpazar','schleem','thonbar', 'arachnio','urfur', 'vertos', 'auther','holik'] colors = 'red green blue'.split() points = {'red': 5, 'green': 10, 'blue': 15} aliens = [{'name': alien, 'color': choice(colors)} for alien in names] # now aliens is a list with dicts, where name and color are attributes # generator expression as argument of the function call sum total_points = sum(points[alien['color']] for alien in aliens) print('Total:', total_points) # written as a classical for-loop total_points = 0 for alien in aliens: color = alien['color'] alien_points = points[color] total_points += alien_points print('Total:', total_points)If you run this program, you get always different results, because of the
random.choice
from colors.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!