标签:ls1 element print 2019 ls year 排行 ls2 2012
def read_file():
with open('2012-19sport.csv', 'r', encoding='utf-8') as data:
# ls1 = data.readline().strip().split(',')
data.readline()
ls2 = []
for line in data.readlines():
ls2.append(line.strip().split(','))
# print(ls1)
# print(ls2)
for i in range(len(ls2)):
ls2[i][0] = ls2[i][0].replace('#', '')
# print(ls2)
# print(ls1 + ls2)
return ls2
def fun1(year, ls):
k = int(input())
ls_one_year = []
for element in ls:
# print(element)
if element[6] == str(year):
ls_one_year.append(element)
for element in ls_one_year[:k]:
print(*element, sep=' | ')
def fun2(ls):
year = int(input())
ls_one_year = []
for item in ls:
if item[6] == str(year):
ls_one_year.append(item)
ls1 = sorted(list(set(item[5] for item in ls_one_year)))
for element in ls1:
print(f'{ls1.index(element) + 1}: {element}')
ls_key = [i for i in range(1, len(ls1) + 1)]
dt1 = dict(zip(ls_key, ls1))
key = int(input())
# print(dt1)
ls_sport = []
for element in ls_one_year:
if element[5] == dt1[key]:
ls_sport.append(element)
# print(ls_sport)
for element in ls_sport:
print(*element, sep=' | ')
ls_pay = []
for element in ls_sport:
ls_pay.append(float(element[2].replace('$', '').replace(' M', '')))
# print(ls_pay)
print('TOTAL: ${:.2f} M'.format(sum(ls_pay)))
if __name__ == '__main__':
ls_return = read_file()
option = input()
try:
option = int(option)
if 2012 <= option <= 2019:
fun1(option, ls_return)
else:
print('Wrong Input')
except Exception as e:
option = option.lower()
if option == 'sport':
fun2(ls_return)
else:
print('Wrong Input')
标签:ls1,element,print,2019,ls,year,排行,ls2,2012 来源: https://blog.csdn.net/Zzzzzz_m/article/details/122766320
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。