python list、dict实例

def get_game_list():
  file = r'D:\xxxx.xls'
  game_classification = []
  # 打开Excel
  data = xlrd.open_workbook(file)
  # 读取第一个sheet
  sheet = data.sheets()[0]
  # 获取总行数
  rows_num = sheet.nrows

  for i in range(rows_num):
    # 获取第i行数据
    rows = sheet.row_values(i)
    game_classification += rows[1].split('、')   --------------list的合并
  print(set(game_classification))

list= {'key1','key2','key3','key4'}

构造一个value为空的字典

dict_cog = dict(map(lambda x: (x, []), list))

 

posted on 2017-08-14 15:58  sunshine_zhf  阅读(147)  评论(0编辑  收藏  举报

导航