0
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 ?

3
  • are you not supposed to do print AccountKey (as opposed to just AccountKey) Commented Dec 29, 2009 at 12:40
  • 1
    It would really help if you specified what the expected output would be. And what happens instead. Commented Dec 29, 2009 at 12:43
  • line[22:2] won't ever return anything, since end of slice is before start. Commented Dec 29, 2009 at 13:04

2 Answers 2

2

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]
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.