Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'attribute': 0.07; 'append': 0.09; 'brackets': 0.09; 'tuple': 0.09; 'am,': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'parentheses': 0.16; 'tuple,': 0.16; 'mon,': 0.16; 'subject:Help': 0.17; 'wrote:': 0.18; 'received:209.85.210.174': 0.21; 'received :mail-iy0-f174.google.com': 0.21; 'header:In-Reply-To:1': 0.22; 'feb': 0.22; 'dictionary': 0.23; 'creating': 0.25; 'variable': 0.28; 'value.': 0.28; 'message-id:@mail.gmail.com': 0.29; 'confused': 0.30; 'chris': 0.30; 'error': 0.30; 'pretty': 0.31; 'values': 0.32; 'does': 0.32; 'list': 0.32; 'instead': 0.33; 'object': 0.33; 'done': 0.34; 'to:addr:python-list': 0.35; 'list:': 0.35; 'but': 0.37; 'received:google.com': 0.37; 'using': 0.37; 'received:209.85': 0.38; 'maps': 0.38; 'received:209': 0.39; 'to:addr:python.org': 0.40; "you've": 0.61; '!!!': 0.64; 'square': 0.67; 'here...': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ryE1NdHKyP9j2KoKDGrw3eBogGKM1cQaJGL5kR7rXuk=; b=eqq0i3UWSnxIdqylXixLj1hsSNWu566TUPvRNv+0MVR2IqZDYL4bD2vDj73IyLhQOS 76rtHCFg48q0k/8Vic5VR5Q7C+99T4XWcp/amRf35xB3SrPkXWmFmrjH/RQi0JG6sHMx KYkeDw9YMpHWOgMGRMzHqjZQNhodGJeQUqVD8= MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 6 Feb 2012 02:20:50 +1100 Subject: Re: Help about dictionary append From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328455252 news.xs4all.nl 6967 [2001:888:2000:d::a6]:37755 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19869 On Mon, Feb 6, 2012 at 2:13 AM, Anatoli Hristov wrote: > Hi there, > > I`m again confused and its the dictionary. As dictionary does not support > append I create a variable list with dictionary key values and want to add > new values to it and then copy it again to the dictionary as I dont know > other methods. A dictionary maps a key to exactly one value. If you want multiples, you do pretty much what you've done here... > mydict = > {'Name':('Name1','Name2','Name3'),'Tel':('023333','037777','049999')} >... > and I get and error that TUPLE object has no attribute Append !!! > > But how to add new Values to a dictionary then ? ... but instead of using parentheses and creating a Tuple, use square brackets and create a List: mydict = {'Name':['Name1','Name2','Name3'],'Tel':['023333','037777','049999']} Then you can append to it, and it will work just fine! Chris Angelico