Jump to content
  • Advertisement
Sign in to follow this  
ryguy4377

[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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
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...

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

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!