[BangPypers] help needed with dictionary
Parthan SR
parth.technofreak at gmail.com
Fri Aug 29 11:24:55 CEST 2008
sunny_plone wrote:
> hi all,
> i am a newbie in python. i was trying to work with dictionaries. i wanted
> to input values through command line and store the values in a dictionary.
> i mean for the same key , multiple values. can any1 suggest me how can i do
> it.....thank you....
>
> i tried this, but the old value is replaced by new one, but i want to store
> al values entered by user.
> kev = {}
> if kev.has_key('Name'):
> kev['Name'].append(person_name)
> print 'name is ', kev['Name']
> else:
> kev['Name'] = [person_name]
> print "kevin's name is %s" % kev['Name']
>
>
>
Can we know what your are intending to do?
kev['Name'].append(person_name)
kev['Name'] will result in a string object and this doesn't have a
method append. You should rather try the following to append the
person_name to kev['Name']
kev['Name'] = kev['Name']+person_name
But as far as dictionary is considered, key is unique and you can not
have same key twice.
--
---
With Regards,
Parthan "technofreak"
<gpg> 2FF01026
<blog> http://blog.technofreak.in
More information about the BangPypers
mailing list