基于人物,物品和商店进行分组

时间:2016-12-03 01:36:35

标签: python python-3.x

我关心的是我的代码没有在python 3.5中运行,它在python 2.7中运行得很好。

问题是我们需要根据以下内容对内容进行分组:

  1. 项目
  2. 存储
  3. 文件Create Table PlazaInsuranceWPDataSet ( PolicyNumber varchar(1), State varchar(3)) Insert Into PlazaInsuranceWPDataSet Values ('A', 'Qld'), ('A', 'NSW'); Create Table #PolicyNumbers (PolicyNumber char(1)); Insert Into #PolicyNumbers Select PolicyNumber From PlazaInsuranceWPDataSet Where State = 'Qld'; -- Returns all policy numbers where at least one row matches the predicate. Select * From PlazaInsuranceWPDataSet As piwp Where Exists (Select 1 From #PolicyNumbers As pn Where pn.PolicyNumber = piwp.PolicyNumber); -- Returns only rows of 'A' that match the filter predicate Select * From PlazaInsuranceWPDataSet Where State = 'Qld'; 中的内容为:

    1511.txt

    输出:

    david book 8 walmart
    mike book 5 kroger
    david food 3  walmart
    mary food 11 target
    

    当我尝试在python 3.5中运行相同的程序时,它给出了以下输出并带有错误:

    'mike': 5, 'mary': 11, 'david': 11
    'food': 14, 'book': 13
    'kroger': 5, 'walmart': 11, 'target': 11
    mike 5
    mary 11
    david 11
    number of items sold by mike is 5
    number of items sold by mary is 11
    number of items sold by david is 11
    total number of food sold 14
    total number of book sold 13
    total number of items sold by kroger is 5
    total number of items sold by walmart is 11
    total number of items sold by target is 11
    

    这是我的代码,如何修改此代码以在Python 3.5中运行?

    'mike': 5, 'david': 11, 'mary': 11
    'food': 14, 'book': 13
    'target': 11, 'walmart': 11, 'kroger': 5
    Traceback (most recent call last):
      File "C:\Users\putch\AppData\Local\Programs\Python\Python35\1511prognew.py", line 20, in <module>
        print(str(d.keys()[i]+" "+str(d.values()[i])))
    TypeError: 'dict_keys' object does not support indexing
    

0 个答案:

没有答案