0

I have a CSV file of statistics that I am running a loop through to get the name, session, amount of time for reps, and count of reps of a person doing push-ups and situps. Each time the loop is run through the list is updated with the next line of statistics. Is there a way to find the average time per session.

**For example output:**
bob session1 average 20 seconds average 10 pushups 
bob session2 average 40 seconds average 18 situps 

**Lists being looped through:**
    lst = ['Bob',session 1, '10seconds', '5 pushups']
    lst = ['Bob',session 1, '30seconds', '15 pushups']
    lst = ['Bob',session 2, '25seconds', '10 situps']
    lst = ['Bob',session 2, '55seconds', '25 situps']

I was thinking of making a key = lst[1] that will record the session and work from there but I can't make sense of how I would do that. Any ideas help, sorry for such a trivial question I am very new.

  • 1
    Does this answer your question? [String formatting in Python](https://stackoverflow.com/questions/517355/string-formatting-in-python) – sushanth Jun 18 '20 at 02:13

1 Answers1

0

use a list of tuples

lst=[('Bob','session 1', '10seconds', '5 pushups'),
    ('Bob','session 1', '30seconds', '15 pushups'),
    ('Bob','session 2', '25seconds', '10 situps'),
    ('Bob','session 2', '55seconds', '25 situps'),]
for item in lst:
    print('{} {} average {}  average {} '.format(item[0],item[1],item[2],item[3]) )
hakim13or
  • 430
  • 5
  • 11