我试图在每行上显示我的列表,每行有 7 个状态,这是我到目前为止所拥有的,但它显示为所有状态的一个长字符串,每个状态都带有引号。我忘了说这是给我的 CS 课的,我们还没有学过 iter,所以我们不允许使用它。给我的唯一提示是将 STATE_LIST 转换为字符串,然后使用 '\n' 将其分解
state = str(STATE_LIST)
displaystates = Text(Point(WINDOW_WIDTH/2, WINDOW_HEIGHT/2), state.split('\n'))
displaystates.draw(win)
STATE_LIST 看起来像这样
STATE_VOTES = {
"AL" : 9, # Alabama
"AK" : 3, # Alaska
"AZ" : 11, # Arizona
"AR" : 6, # Arkansas
"CA" : 55, # California
"CO" : 9, # Colorado
"CT" : 7, # Connecticut
"DE" : 3, # Delaware
"DC" : 3, # Washington DC
"FL" : 29, # Florida
"GA" : 16, # Georgia
"HI" : 4, # Hawaii
"ID" : 4, # Idaho
"IL" : 20, # Illinois
"IN" : 11, # Indiana
"IA" : 6, # Iowa
"KS" : 6, # Kansas
"KY" : 8, # Kentucky
"LA" : 8, # Louisiana
"ME" : 4, # Maine
"MD" : 10, # Maryland
"MA" : 11, # Massachusetts
"MI" : 16, # Michigan
"MN" : 10, # Minnesota
"MS" : 6, # Mississippi
"MO" : 10, # Missouri
"MT" : 3, # Montana
"NE" : 5, # Nebraska
"NV" : 6, # Nevada
"NH" : 4, # New Hampshire
"NJ" : 14, # New Jersey
"NM" : 5, # New Mexico
"NY" : 29, # New York
"NC" : 15, # North Carolina
"ND" : 3, # North Dakota
"OH" : 18, # Ohio
"OK" : 7, # Oklahoma
"OR" : 7, # Oregon
"PA" : 20, # Pennsylvania
"RI" : 4, # Rhode Island
"SC" : 9, # South Carolina
"SD" : 3, # South Dakota
"TN" : 11, # Tennessee
"TX" : 38, # Texas
"UT" : 6, # Utah
"VT" : 3, # Vermont
"VA" : 13, # Virginia
"WA" : 12, # Washington
"WV" : 5, # West Virginia
"WI" : 10, # Wisconsin
"WY" : 3 # Wyoming
}
STATE_LIST = sorted(list(STATE_VOTES.keys()))
我试图让它看起来像这样