Skip to main content
GameDev.net gamedev.net
🔒 Locked

[FIGURED OUT]

Started by ryguy4377 Mar 22, 2007 at 11:54 AM 5 replies 900+ views
Original Post
ryguy4377
ryguy4377
Hello...I have been trying to write a simple program that can save and load lists. I am not very experienced with python at all, and so I seem to have gotten stuck at this point... What I'm trying to do is read a list that looks like this:

logList=[
['date','name','quantity','cost','total'],
['date2','name2','quantity2','cost2','total2'],
]
..and then add up all the "totals" in that list. The code I was trying to do it with is:

def getTotal():
    for date,name,quant,cost,total in logList :
        rtm2 = total
        runttlent.delete(0, END)
        runttlent.insert(0, rtm2)
That inserts rtm2 into an entry widget (using Tkinter..). Now, as you probably guessed, "rtm2 = total" only gives me a single value...I have no idea how to add up every value in the 'total' spot on that list :-/. Any help would be appreciated...thanks in advance. [Edited by - ryguy4377 on March 22, 2007 12:33:50 PM]
Kylotan
Kylotan
How would you add up those totals, when the values you posted are strings?

And, how many totals are you wanting? Your description makes it sound like you want to add a single total, but your code implies that you want to add several totals to a list. It's hard to work out what you actually mean.
ryguy4377
ryguy4377
Quote:
Original post by Kylotan
How would you add up those totals, when the values you posted are strings?

And, how many totals are you wanting? Your description makes it sound like you want to add a single total, but your code implies that you want to add several totals to a list. It's hard to work out what you actually mean.


Yeah...I was afraid of that. Ok, I'll try to make it more clear:

Is there any way that you can get the values in the "total" spot for that list of the strings I posted? I need to be able to do something that adds up all the "total" values in all those strings.

I don't know if that makes it any clearer :-/...like I said, I'm not too experienced with any of this...
ryguy4377
ryguy4377
Ahh wait...I think I've figured it out =)
Oluseyi
Oluseyi
Care to share?

Care to not change your thread topic in the future, so that someone else searching for the same issue can take advantage of your experiences?
Alpha_ProgDes
Alpha_ProgDes
To expand on that. If you have a problem and you figure it out, then let the rest of us know how you did it. Why? Because someone WILL have the same problem as you, and will need a solution just as you did.

In other words, it's good to share. SO SHARE [flaming]
Beginner in Game Development?  Read here. And read here.  
Beer Hunter
Beer Hunter
I'm taking a guess here that what he was looking for was sum(t[4] for t in logList).

[Edited by - Beer Hunter on March 23, 2007 5:28:15 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.