473,473 Members | 1,419 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Append data to a list within a dict

Hello group,

Say I have the following dictionary:

ListDict = {
'one' : ['oneone' , 'onetwo' , 'onethree'],
'two' : ['twoone' , 'twotwo', 'twothree'],
'three' : ['threeone' , 'threetwo', threethree']}

Now I want to append 'twofour' to the list of the 'two' key but I can't
figure out how to that?
Some pointers would be greatly appreciated.

Thanks
Tina
Apr 14 '07 #1
9 62170

On Apr 14, 2007, at 12:39 AM, Tina I wrote:
Say I have the following dictionary:

ListDict = {
'one' : ['oneone' , 'onetwo' , 'onethree'],
'two' : ['twoone' , 'twotwo', 'twothree'],
'three' : ['threeone' , 'threetwo', threethree']}

Now I want to append 'twofour' to the list of the 'two' key but I
can't
figure out how to that?
Some pointers would be greatly appreciated.
ListDict['two'].append('twofour')

But you'll have to insert the missing single quote before
"threethree" first.

hope this helps,
Michael
Apr 14 '07 #2
Tina I <ti*****@bestemselv.comwrites:
ListDict = {
'one' : ['oneone' , 'onetwo' , 'onethree'],
'two' : ['twoone' , 'twotwo', 'twothree'],
'three' : ['threeone' , 'threetwo', threethree']}

Now I want to append 'twofour' to the list of the 'two' key but I
can't figure out how to that?
Is this a class exercise? Hint:
1) figure out how to access the list of the 'two' key
2) append 'twofour' to it.
Apr 14 '07 #3
On Apr 13, 11:39 pm, Tina I <tina...@bestemselv.comwrote:
Hello group,

Say I have the following dictionary:

ListDict = {
'one' : ['oneone' , 'onetwo' , 'onethree'],
'two' : ['twoone' , 'twotwo', 'twothree'],
'three' : ['threeone' , 'threetwo', threethree']}

Now I want to append 'twofour' to the list of the 'two' key but I can't
figure out how to that?
Some pointers would be greatly appreciated.

Thanks
Tina

ListDict["two"] returns the list. So you can do this:

lst = listDict["two"]
lst.append("twofour")

or you can do it directly like this:

ListDict["two"].append("twofour")
Apr 14 '07 #4

On Apr 14, 2007, at 12:51 AM, Paul Rubin wrote:
Is this a class exercise? Hint:
1) figure out how to access the list of the 'two' key
2) append 'twofour' to it.
damn.
Apr 14 '07 #5
Paul Rubin wrote:
Tina I <ti*****@bestemselv.comwrites:
>ListDict = {
'one' : ['oneone' , 'onetwo' , 'onethree'],
'two' : ['twoone' , 'twotwo', 'twothree'],
'three' : ['threeone' , 'threetwo', threethree']}

Now I want to append 'twofour' to the list of the 'two' key but I
can't figure out how to that?

Is this a class exercise? Hint:
1) figure out how to access the list of the 'two' key
2) append 'twofour' to it.
He he... at the age of 40 I'm well beyond school work ;)
But thanks anyway

Tina
Apr 14 '07 #6
Michael Bentley wrote:
>
On Apr 14, 2007, at 12:39 AM, Tina I wrote:
>Say I have the following dictionary:

ListDict = {
'one' : ['oneone' , 'onetwo' , 'onethree'],
'two' : ['twoone' , 'twotwo', 'twothree'],
'three' : ['threeone' , 'threetwo', threethree']}

Now I want to append 'twofour' to the list of the 'two' key but I can't
figure out how to that?
Some pointers would be greatly appreciated.

ListDict['two'].append('twofour')

But you'll have to insert the missing single quote before "threethree"
first.

hope this helps,
Michael
Great! Thanks!
And the missing singlequote was just a typo, my actual dictionary is way
bigger so I just made up this as an example.

Tina
Apr 14 '07 #7
"Tina I" <ti,,eb@be...elv.comwrote:

Hello group,

Say I have the following dictionary:

ListDict = {
'one' : ['oneone' , 'onetwo' , 'onethree'],
'two' : ['twoone' , 'twotwo', 'twothree'],
'three' : ['threeone' , 'threetwo', threethree']}

Now I want to append 'twofour' to the list of the 'two' key but I can't
figure out how to that?
Some pointers would be greatly appreciated.
Just do it:

ListDict['two'].append('twofour')

This works because ListDict['two'] is a list...

- Hendrik

Apr 14 '07 #8
Tina I <ti*****@bestemselv.comwrote:
...
He he... at the age of 40 I'm well beyond school work ;)
Why would that be? My wife's over 40, yet she's a student (currently at
Stanford -- they were overjoyed to admit her, with lot of life
experience as well as previous studies, apparently). She's not taking
elementary courses on Python (having co-written a book on Python,
tech-reviewed a few, and having been the first woman coopted as a member
of the PSF:-), but she _has_ been taken equivalent ones on Java and C++
(languages she didn't previously know), as well as calculus,
neurophysiology, and other strange things that are part of the "Symbolic
Systems" studies.

Down with ageism!-)
Alex

Apr 15 '07 #9
Alex Martelli wrote:
Tina I <ti*****@bestemselv.comwrote:
...
>He he... at the age of 40 I'm well beyond school work ;)

Why would that be? My wife's over 40, yet she's a student (currently at
Stanford -- they were overjoyed to admit her, with lot of life
experience as well as previous studies, apparently). She's not taking
elementary courses on Python (having co-written a book on Python,
tech-reviewed a few, and having been the first woman coopted as a member
of the PSF:-), but she _has_ been taken equivalent ones on Java and C++
(languages she didn't previously know), as well as calculus,
neurophysiology, and other strange things that are part of the "Symbolic
Systems" studies.

Down with ageism!-)
Alex
It's not really ageism, just how I feel *my self* about going back to
school. I'm not done learning though, it's just that I can give my self
the luxury of learning whatever I want, just what I want at the pace
that I want. And since I happen to like computers that's mostly what I
concentrate about. Right now I'm hooked on Python, but also messing
about with PHP and Javascript. Tried some Java but didn't like it...
Threw out Windows a couple of years ago and have spent quite some time
learning the ins and outs of Linux.

So even if I probably will never go back to school I'm looking forward
to many many years learning new and exciting things :)

Tina
(Sorry for the way OT post. I just couldn't stop my own ramble ;)
Apr 15 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: tertius | last post by:
Is there a better way to append certain chars in a string with a backslash that the example below? chr = "#$%^&_{}" # special chars to look out for str = "123 45^ & 00 0_" # string to...
3
by: waters | last post by:
I seem to have hit a snag. I am trying to add the list (l_local) as an item in the output list (l_output). "l_local" is a modified copy of the format-list "l_format", which will be updated by...
5
by: Carlos Ribeiro | last post by:
Hello all, I'm posting this to the list with the intention to form a group of people interested in this type of solution. I'm not going to spam the list with it, unless for occasional and...
1
by: Alexander Kervero | last post by:
Hi ,today i was reading diveinto python book,in chapter 5 it has a very generic module to get file information,html,mp3s ,etc. The code of the example is here :...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
3
by: wvmbark | last post by:
First time poster... I just found this forum and it appears there's plenty of people here that could make short work of problem that's been driving me absolutely bonkers for months. Every day we...
10
by: HYRY | last post by:
I have the following questions, I am using Python 2.4.2 19167152 #1 11306608 #1 1. the address of a.append and list.append is different, can I get the address of...
4
by: franc sutherland | last post by:
Hello, I am using Access 2003. I am having trouble trapping the "can't append all the records in the append query" error message when appending data to a query from a table which is linked to...
20
by: Pat | last post by:
I know it's not "fair" to compare language features, but it seems to me (a Python newbie) that appending a new key/value to a dict in Python is awfully cumbersome. In Python, this is the best...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.