Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.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.055 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.00; 'element': 0.07; 'subject:file': 0.07; 'cc:addr:python-list': 0.11; 'appreciated!': 0.16; 'cc:name:python list': 0.16; 'subject:.txt': 0.16; 'tuple': 0.16; 'value.': 0.19; 'cc:addr:python.org': 0.22; 'subject: .': 0.24; 'looks': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'header :In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'subject:from': 0.34; 'received:google.com': 0.35; 'manufacturer': 0.36; 'should': 0.36; 'list': 0.37; 'how': 0.40; 'to:addr:gmail.com': 0.65; 'here': 0.66; 'sample': 0.67; 'containing': 0.69; 'car': 0.72; 'd[2]': 0.84; 'washington': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=0FeAMOPUwFk7e3Fd+owCmvIfx17CrE62M/zIyfKehzg=; b=kqtGsaWSgpYeKqa/HYek8zRpVt7s22bHLj3NtpERUTTjyUr4qgMIFAT4ogyA8+g1XU UR1NUS54R/9NTy/7g1DQ0wFyyVeL/+THiNf8kxChOnp7PTaZBFBDkuYBYs4fDWrGzzE6 zmfX/8Lyl8vwq/M3CNhEQzjJwFLcHxLP2WCrbHTqnGZKFztm1cw2cbBr4mnF+oubZTUv lmiqDwBbtOqxsoTFjn23E9/lx9KOPVSNGXamTgBtXbyASwcohgvjIhpSrYa+mfVm7C0I aisO33XhieoDDCmUJ3/1eS/GVLExAlHITvZ2YHLwyFqdMBM7zkd97Zjt5qEpqRtUW9aU TEQA== MIME-Version: 1.0 X-Received: by 10.180.77.66 with SMTP id q2mr6311450wiw.13.1364746825529; Sun, 31 Mar 2013 09:20:25 -0700 (PDT) In-Reply-To: References: Date: Sun, 31 Mar 2013 09:20:25 -0700 Subject: Re: Creating a dictionary from a .txt file From: Mark Janssen To: "C.T." Content-Type: multipart/alternative; boundary=f46d04389405be809e04d93ae19b Cc: Python List 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: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364746832 news.xs4all.nl 6927 [2001:888:2000:d::a6]:47885 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42379 --f46d04389405be809e04d93ae19b Content-Type: text/plain; charset=ISO-8859-1 > > Every line is now an element in list d. The question I have now is how can > I make a dictionary out of the list d with the car manufacturer as the key > and a tuple containing the year and the model should be the key's value. > Here is a sample of what list d looks like: > > ['1899 Horsey Horseless', '1909 Ford Model T', '1911 Overland OctoAuto', > '2003 Hummer H2', '2004 Chevy SSR'] > > Any help would be appreciated! > > As long as your data is consistently ordered, just use list indexing. d[2] is your key, and (d[1],d[3]) the key's value. Mark Tacoma, Washington --f46d04389405be809e04d93ae19b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Every line is now an element in list d. The ques= tion I have now is how can I make a dictionary out of the list d with the c= ar manufacturer as the key and a tuple containing the year and the model sh= ould be the key's value. Here is a sample of what list d looks like:
['1899 Horsey Horseless', '1909 Ford Model T', '1911 Ov= erland OctoAuto', '2003 Hummer H2', '2004 Chevy SSR']
Any help would be appreciated!


As long as your data is consistently ordered, just use list indexing. =A0= d[2] is your key, and (d[1],d[3]) the key's value.

Mark
Tacoma, Washington
--f46d04389405be809e04d93ae19b--