473,499 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

list behavior

Hello everybody,

I needed to add a list to a dictionary, something very simple:
d = {}
l = []
l.append(1)
d["one"] = l
d {'one': [1]}

Buen, when I just move the 'append' statement to the dictionary
assigment then: l = []
d = {}
d["one"] = l.append(1)
d

{'one': None}

Not what I expected, then I came to the conclusion that
[].append(value) returns 'None', why?

Rene A.
Jul 18 '05 #1
1 1327
Rene Aguirre wrote:
Hello everybody,

I needed to add a list to a dictionary, something very simple:
d = {}
l = []
l.append(1)
d["one"] = l
d
{'one': [1]}

Buen, when I just move the 'append' statement to the dictionary
assigment then:
l = []
d = {}
d["one"] = l.append(1)
d


{'one': None}

Not what I expected, then I came to the conclusion that
[].append(value) returns 'None', why?

Rene A.


append is what is called procedure in other languages.

d["one"].append(1) should work

hth,
anton.

Jul 18 '05 #2

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

Similar topics

23
40589
by: Fuzzyman | last post by:
Pythons internal 'pointers' system is certainly causing me a few headaches..... When I want to copy the contents of a variable I find it impossible to know whether I've copied the contents *or*...
34
3246
by: jblazi | last post by:
Let us assume I have a list like and would like to transoform it into the string '{1,2},{7,8},{12,13}' Which is the simplest way of achiebing this? (The list is in fact much longer and...
18
5414
by: Makis Papapanagiotou | last post by:
Hello all, There is a strange case where a class Test is composed from three objects of other classes. i.e. class Test { public: Test(); private: Point x;
7
2144
by: dam_fool_2003 | last post by:
friends, I wanted to learn the various ways of inserting a single list. so: Method 1: #include<stdlib.h> #include<stdio.h> struct node { unsigned int data; struct node *next;
38
2061
by: Steven Bethard | last post by:
> >>> aList = > >>> it = iter(aList) > >>> zip(it, it) > > That behavior is currently an accident. >http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=1121416
27
79882
by: Tripper | last post by:
Which is the better way to go and why? //trivial example List<string> strings = GetStrings(); foreach (string s in strings) { // some operation; } strings.ForEach(
6
3693
by: Jason S | last post by:
where is the behavior of list::iterator specified? I need to keep track of ranges of data, all I can figure out so far is that iterators are guaranteed to be valid unless you remove the elements...
35
5826
by: Lee Crabtree | last post by:
This seems inconsistent and more than a little bizarre. Array.Clear sets all elements of the array to their default values (0, null, whatever), whereas List<>.Clear removes all items from the...
4
3383
by: jmartmem | last post by:
Greetings, I have an ASP page containing a Record Insertion Form with a number of fields (mostly text fields and list/menu fields) linked to an Access database. I've created an onsubmit behavior...
0
1066
by: Steve Holden | last post by:
Hamish McKenzie wrote: Vector(1, 2, 3) fails for exactly the same reasons as list: Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: list() takes at most 1...
0
7014
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
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
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5485
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,...
0
4609
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
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.