Skip to content

Instantly share code, notes, and snippets.

@mayankdawar
Created August 15, 2020 16:11
Show Gist options
  • Save mayankdawar/ec4f2accf900fc3d0b6fadf824c21a6e to your computer and use it in GitHub Desktop.
Save mayankdawar/ec4f2accf900fc3d0b6fadf824c21a6e to your computer and use it in GitHub Desktop.
Below, we have provided a species list and a population list. Use zip to combine these lists into one list of tuples called pop_info. From this list, create a new list called endangered that contains the names of species whose populations are below 2500.
species = ['golden retriever', 'white tailed deer', 'black rhino', 'brown squirrel', 'field mouse', 'orangutan', 'sumatran elephant', 'rainbow trout', 'black bear', 'blue whale', 'water moccasin', 'giant panda', 'green turtle', 'blue jay', 'japanese beetle']
population = [10000, 90000, 1000, 2000000, 500000, 500, 1200, 8000, 12000, 2300, 7500, 100, 1800, 9500, 125000]
pop_info = zip(species,population)
endangered = [x1 for x1,x2 in pop_info if x2< 2500]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment