Average of entries in a list of lists
davea at ieee.org
Thu Sep 24 14:18:52 CEST 2009
> I'm a bit of a newbie to python, so this may very well be a basic question:
> I have a list of lists, with around 1000 lists looking like this:
> ['0.000744', '0.480106', 'B'].
> I need the average of the first to entries of all the lists, can anybody
> help how me to do this?
> Thanks in advance,
"first to entries" probably is intended to be "first two entries" This
is the same typo you made when you cross-posted on python-tutor.
Have you made a sample program (script) that partially works? Show us
what you've done, and explain what's wrong with it. Usually by that
time, you'll figure it out yourself, and learn more. But if you're
really stuck, and not just wanting someone else to do tonight's
homework, show us what you've got.
Start with a program that defines a list of maybe 4 lists (you can
change it to 1000 later). Just enough data that you can see the
algorithm working. Then write some form of loop that you think might
accomplish the result, or at least a subset of the result. Show us that
code, and its output, and explain why it falls short.
And of course, tell us the Python version and OS environment you're
running in. You'd be surprised how often that matters.
More information about the Python-list