Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Mark Lawrence Newsgroups: comp.lang.python Subject: Re: Finding scores from a list Date: Tue, 24 Nov 2015 13:44:47 +0000 Lines: 32 Message-ID: References: <277843f7-c898-4378-85ea-841b09a289e3@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de jJ3pg+CaglPCgy68RxU3AAqYdmkyDNyVHyFhxXuwKTBg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.05; 'indices': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'typeerror:': 0.09; 'digest': 0.15; 'hint': 0.16; 'integers,': 0.16; 'received:194.126': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'language': 0.19; '"",': 0.22; 'lawrence': 0.22; 'tried': 0.24; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'subject:list': 0.26; 'header:X -Complaints-To:1': 0.26; 'earlier': 0.27; 'error': 0.27; 'compare': 0.27; 'str': 0.29; 'language.': 0.32; 'traceback': 0.33; 'structure': 0.34; 'file': 0.34; 'this?': 0.34; 'list': 0.34; 'skip:p 30': 0.35; 'but': 0.36; 'instead': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'there,': 0.37; 'received:org': 0.37; 'thank': 0.38; 'data': 0.39; 'subject:from': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'your': 0.60; 'received:194': 0.61; 'charset:windows-1252': 0.62; 'spot': 0.63; 'our': 0.64; 'results': 0.66; 'today.': 0.67; 'pythonistas,': 0.84; 'score.': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: 107.93.126.194.pool.dsl.daisyplc.net User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 In-Reply-To: <277843f7-c898-4378-85ea-841b09a289e3@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99330 On 24/11/2015 13:25, Cai Gengyang wrote: > > results = [ > {"id": 1, "name": "ensheng", "score": 10}, > {"id": 2, "name": "gengyang", "score": 12}, > {"id": 3, "name": "jordan", "score": 5}, > ] > > I want to find gengyang's score. This is what I tried : > >>>> print((results["gengyang"])["score"]) > > but I got an error message instead : > > Traceback (most recent call last): > File "", line 1, in > print((results["gengyang"])["score"]) > TypeError: list indices must be integers, not str > > Any ideas how to solve this? Thank you .. > Please read and digest the TypeError. There is a very strong hint in there, follow it. Compare the type of your data structure `results` with the one you've used earlier today. Spot the difference? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence