# [FIGURED OUT]

This topic is 4165 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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]

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by KylotanHow 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...

##### Share on other sites
Ahh wait...I think I've figured it out =)

##### Share on other sites
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?

##### Share on other sites
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]

##### Share on other sites
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]

1. 1
2. 2
frob
17
3. 3
4. 4
5. 5

• 20
• 13
• 14
• 76
• 22
• ### Forum Statistics

• Total Topics
632140
• Total Posts
3004373

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!