Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following code extracts the city populations that are larger than 10000 from the list of lists populationsSK and stores them in a new list

The following code extracts the city populations that are larger than 10000 from the list of lists populationsSK and stores them in a new list citiesSK.

populationsSK = [ [ Pelican Narrows , 2703] ,

[ Saskatoon , 222035] ,

[ Moose Jaw , 33617] ,

[ La Ronge , 5905] ]

citiesSK = []

for x in populationsSK :

if x [1] >= 10000:

citiesSK . append ( x )

At the end of the program, citiesSK is the list: [[Saskatoon, 222035], [Moose Jaw, 33617]]

(a) Modify the code so that it is an equivalent program in which the list citiesSK is created using a list comprehension instead of a loop.

(b) Using a similar list comprehension, write an expression that creates a list of all the towns whose population is smaller than 40000.

(c) Using a list comprehension, write an expression that creates a list of the all the names of the cities and towns (the new list should contain all the names, but no population data)

(d) Using a list comprehension, write an expression that creates a list of all the towns and cities whose names are more than 8 characters (including blanks).

(This is Python Programming)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 1 Lnai 9284

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Carlos Soares ,Joao Gama ,Alipio Jorge

1st Edition

3319235273, 978-3319235271

More Books

Students also viewed these Databases questions

Question

2. Do you find change a. invigorating? b. stressful? _______

Answered: 1 week ago

Question

How was their resistance overcome?

Answered: 1 week ago