[program-l] python, Getting X number of a certain value from a list of dictionaries?

  • From: Al Puzzuoli <alpuzz@xxxxxxxxx>
  • To: Program L <program-l@xxxxxxxxxxxxx>
  • Date: Thu, 04 Oct 2012 20:36:51 -0400

HI everyone,
This seems like it should be really simple, but if there's a way to do this with a single statement, the syntax is eluding me. Basically, I have a list of dictionaries called day. So I can reference things like: "day[0] ['High']", or "day[1] ['Date]". But, if I want to extract a list of 20 of a particular item, say the closing price over the last 20 days, what's the quickest way to do that? I know I could use some sort of iterative loop, but aren't there any list slicing commands that would work? For example, I know I can get the first 20 dictionaries by doing something like "l=day[:21]", so can't I be more specific, "l=day[:21] ['Close']? If so, I can't for the life of me figure out the syntax.
Thanks for any help on this one,

Al

** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

Other related posts: