Help please, im using python 3 and im trying to print the state with maximum and minimum population from a text file...This is what the text file contains.

Alabama
AL
4802982
Alaska
AK
721523
Arizona
AZ
6412700
Arkansas
AR
2926229
California
CA
37341989
Colorado
CO
4939456
Connecticut
CT
3581628
Delaware
DE
900877
Florida
FL
18900773
Georgia
GA
9727566
Hawaii
HI
1366862
Idaho
ID
1573499
Illinois
IL
12864380
Indiana
IN
6501582
Iowa
IA
3053787
Kansas
KS
2863813
Kentucky
KY
4350606
Louisiana
LA
4553962
Maine
ME
1333074
Maryland
MD
5789929
Massachusetts
MA
6559644
Michigan
MI
9911626
Minnesota
MN
5314879
Mississippi
MS
2978240
Missouri
MO
6011478
Montana
MT
994416
Nebraska
NE
1831825
Nevada
NV
2709432
New Hampshire
NH
1321445
New Jersey
NJ
8807501
New Mexico
NM
2067273
New York
NY
19421055
North Carolina
NC
9565781
North Dakota
ND
675905
Ohio
OH
11568495
Oklahoma
OK
3764882
Oregon
OR
3848606
Pennsylvania
PA
12734905
Rhode Island
RI
1055247
South Carolina
SC
4645975
South Dakota
SD
819761
Tennessee
TN
6375431
Texas
TX
25268418
Utah
UT
2770765
Vermont
VT
630337
Virginia
VA
8037736
Washington
WA
6753369
West Virginia
WV
1859815
Wisconsin
WI
5698230
Wyoming
WY
568300

Recommended Answers

All 2 Replies

A block of python code, showing serious attempts to solve the problem is missing in your question. Helpers here are not attending a programming course, and usually don't do student's homework for them.

Here you are. I hope, this makes you a really good programmer.

f=open("states.txt").readlines()
states=sorted([(f[i].strip(),f[i+1].strip(),int(f[i+2])) for i in range(0,len(f)-3,3)],key=lambda x:x[2])
print("minimum population:",states[0])
print("maximum population:",states[-1])
commented: Thank u very much, I really appreciate it. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.