question about dictionary type..

eugene kim eugene1977 at hotmail.com
Sun Sep 15 04:52:20 CEST 2002


thank you.. i just checked replies..
i haven't tried them..
this is what i came up with..
(making needed tables first.. as carl and padraig said)
i'm having one problem(described below)


d4 = {}
for line in stdin.readlines():
    words = split(line)
    if len(words) > 0 :
        if words[0] == 'call' :
            games = games + 1
        elif words[0][0] == ')':
            table1 = {}
            table2= {}
            table3 = {}
            table1[dataList[3]] = 0
            table2[dataList[2]] = table1
            table3[dataList[0]] = table2
            table3[dataList[1]] = table2

            for i in [dataList[0], dataList[1]]:
                if not d4.has_key(i) :
                    d4[i] = table2
                else:
                    if not d4[i].has_key(dataList[2]):
                        d4[i][dataList[2]] = table1
                    else:
                        if not d4[i][dataList[2]].has_key(dataList[3]):
                            d4[i][dataList[2]][dataList[3]] = 0
            print d4
            dataList = []

        else:
            aList = []
            for i in words:
                i = (upper(replace(replace(i, '\'', ''), ',' ,'')))
                aList.append(i)
            
            dataList.append(join(aList))

input looks like this..
-------------------------------------
call games_view_insert (
'California',
'Baylor',
'football',
'm',
'31-Aug-02',
'Berkeley, Calif.',
'-1',
'-1'
);

call games_view_insert (
'Baylor',
'Samford',
'football',
'f',
'07-Sep-02',
'Waco, Texas',
'-1',
'-1'
);

call games_view_insert (
'New Mexico',
'Baylor',
'football',
'm',
'14-Sep-02',
'Albuquerque, N.M.',
'-1',
'-1'
);
--------------------------------------------
this is output..in each loop ( print d4)
problem is california should have had 'M' only, not 'F'emale team..

{'BAYLOR': {'FOOTBALL': {'M': 0}}, 'CALIFORNIA': {'FOOTBALL': {'M': 0}}}
{'BAYLOR': {'FOOTBALL': {'M': 0, 'F': 0}}, 'CALIFORNIA': {'FOOTBALL': {'M': 
0, 'F': 0}}, 'SAMFORD': {'FOOTBALL': {'F': 0}}}
{'BAYLOR': {'FOOTBALL': {'M': 0, 'F': 0}}, 'CALIFORNIA': {'FOOTBALL': {'M': 
0, 'F': 0}}, 'NEW MEXICO': {'FOOTBALL': {'M': 0}}, 'SAMFORD': {'FOOTBALL': 
{'F': 0}}}






More information about the Python-list mailing list