Question: Please Solve Using Python Programming. 1. Use list comprehension to simplify the code. names = [George Boole, Charles Babbage, Grace Hopper] lastNames = [] for
Please Solve Using Python Programming.
1. Use list comprehension to simplify the code.
names = ["George Boole", "Charles Babbage", "Grace Hopper"] lastNames = [] for name in names: lastNames.append(name.split()[-1])
Describe the output displayed by the lines of code, where the file States.txtcontains the 50 U.S. states in the order they joined the union.
2.
infile = open("States.txt", 'r') print([line.rstrip().upper() for line in infile]) 3.
infile = open("States.txt", 'r')
print(sorted([line.rstrip() for line in infile], key=len))
4. New England StatesWrite a program that displays the names of the states in the list NE in descending order by land area. See Fig. 4.17.
Sorted by land area in descending order: Maine Vermont New Hampshire Massachusetts Connecticut Rhode Island
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
