Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.046 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'subject:Python': 0.06; 'rewrite': 0.09; 'expression,': 0.16; 'states)': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'thu,': 0.19; 'subject:Code': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'could': 0.34; 'received:google.com': 0.35; 'doing': 0.36; 'list': 0.37; 'list.': 0.37; 'to:addr:python- list': 0.38; 'list,': 0.38; 'to:addr:python.org': 0.39; 'helps': 0.61; 'line,': 0.68; 'sum.': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=8X7fjTEpcLeVaZvRCu6+4lvOptBVS8IqoE7yIZ2jNJY=; b=Tlkrmv1uoNFmKGDBbcovzFWP/9cYoMYZ0sYSgXvbSZnwH+6UsMlD0ao/P1ZjmZ0la/ Fkqm95B00hg+2qhj7WvnUwGPAYqLgWlb8acYdfhIVKq80LYwPbkhYVIVIaYwHLsl3m5T 3iakEI2vpVo5KMyETEwe/U6AZ5nAZtvJrD4gF5ja9mXfvp1ozKWtxB7b28FIdwmQfHMQ Tyw17aDVm1lnRCgOO7qpnrmabOBjhvkI7m9Q5n1dV+qIRgQ8L1/uTCtcIK1G/+kXfnL2 RJTpkmhOmDJMTXDJzN2UmjPNr2ZXqxOkgvWWEYAzwuGjocYnfP0maaXq8n//q0XIEjzD UhrQ== X-Received: by 10.236.65.227 with SMTP id f63mr8063614yhd.13.1403187023182; Thu, 19 Jun 2014 07:10:23 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <4045d8ca-923d-4384-a684-57cbd80ab7b7@googlegroups.com> <03a82bc4-340f-4b16-8dbb-791b706c7862@googlegroups.com> From: Ian Kelly Date: Thu, 19 Jun 2014 08:09:42 -0600 Subject: Re: Understanding Python Code To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1403187031 news.xs4all.nl 2967 [2001:888:2000:d::a6]:43843 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73433 On Thu, Jun 19, 2014 at 3:48 AM, wrote: > I am trying to see this line, > prev_f_sum = sum(f_prev[k]*a[k][st] for k in states) > > a[k][st], and f_prev[k] I could take out and understood. > Now as it is doing sum() so it must be over a list, > I am trying to understand the number of entities in the list, thinking whether to put len(), and see for which entities it is doing the sum. It's summing a generator expression, not a list. If it helps to understand it, you could rewrite that line like this: values_to_be_summed = [] for k in states: values_to_be_summed.append(f_prev[k]*a[k][st]) prev_f_sum = sum(values_to_be_summed) So the number of entities in the list is len(states).