views:

133

answers:

2
f = open('transaction.log','r')

ClerkHash = dict()
 arr = [0,0]

for line in f:
    Tdate        = line[0:12] 
    AccountKey   = line[12:50]
    TransType    = line[22:2]
    ClerkKey     = line[24:10]
    CurrencyCode = line[34:2]
    Amount       = line[36:45]
    print line
    print '\n'
    print AccountKey 
    print '\n'
    print Tdate         print '\n'

    if TransType=="04":
        ClerkHash[ClerkKey+AccountKey] = arr; // is this line corrent ? i don't want to corrupt the array every time ? how should i do it ?
        ClerkHash[ClerkKey+AccountKey][0]+=1 
        ClerkHash[ClerkKey+AccountKey][1]+= Amount


for Key in ClerkHash.keys():
     if ClerkHash[key][0] >= 3 and ClerkHash[key][1] > 1000:
        print Key

i want to have an hash name ClerkHash[ClerkKey+AccountKey] which consistes of array of 2 int : first index is withdrawl num , and second is ammount did i defined the array and hash well ? in addition i want to sum the ammount...how can i do it ?

+1  A: 

Here is few issue I seen so far

Amount       = line[36:45]

should be

Amount       = int(line[36:45])

and

ClerkHash[ClerkKey+AccountKey] = arr[0,0]

should be

ClerkHash[ClerkKey+AccountKey] = [0,0]
S.Mark
A: 

Check your slice intervals! The second argument is another index, NOT the number of steps to take from the first index. I guess

TransType    = line[22:2]

should rather be

TransType = line[22:24]

You overwrite values if you set

ClerkHash[ClerkKey+AccountKey] = [0, 0]

each time you encounter TransType == "04". So change

if TransType=="04":
        ClerkHash[ClerkKey+AccountKey] = arr[0,0]
        ClerkHash[ClerkKey+AccountKey][0]+=1 
        ClerkHash[ClerkKey+AccountKey][1]+= Amount

to

if TransType=="04":
    if not ClerkHash.has_key(ClerkKey+AccountKey):
        ClerkHash[ClerkKey+AccountKey] = [1, Amount]
    else:
        ClerkHash[ClerkKey+AccountKey][0] += 1 
        ClerkHash[ClerkKey+AccountKey][1] += Amount
jellybean