473,578 Members | 3,177 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

list1.append(li st2) returns None

def enlargetable(ta ble,col):
return table.append(co l)

def removecolfromta ble(table,col):
return table.remove(co l)

print enlargetable([[1],[2],[3]],[4]) # returns None

Why does it return None instead of [[1],[2],[3],[4]] which I expected?
Dec 21 '06 #1
9 2289
Pyenos wrote:
def enlargetable(ta ble,col):
return table.append(co l)

def removecolfromta ble(table,col):
return table.remove(co l)

print enlargetable([[1],[2],[3]],[4]) # returns None

Why does it return None instead of [[1],[2],[3],[4]] which I expected?
append modifies the list and then returns None:
>>print a
[1, 2, 3]
>>print a.append(4)
None
>>print a
[1, 2, 3, 4]
The reasoning given at
http://www.python.org/doc/faq/genera...he-sorted-list
is so you wont do something like this:

a = [1,2,3]
b = a.append(4)

and assume that a is still [1,2,3]
More discussion on this topic is available at
http://groups.google.com/group/comp....b2e67550123b92

Todd

Dec 21 '06 #2

Pyenos wrote:
def enlargetable(ta ble,col):
return table.append(co l)

def removecolfromta ble(table,col):
return table.remove(co l)

print enlargetable([[1],[2],[3]],[4]) # returns None

Why does it return None instead of [[1],[2],[3],[4]] which I expected?
return the table. Ex:

def enlargetable(ta ble, col):
table.append(co l)
return table

Dec 21 '06 #3
def enlargetable(ta ble,col):
return table.append(co l)
Google for "python pitfalls"

--
Gabriel Genellina

Dec 21 '06 #4
Pyenos <py****@pyenos. orgwrites:
def enlargetable(ta ble,col):
return table.append(co l)

def removecolfromta ble(table,col):
return table.remove(co l)

print enlargetable([[1],[2],[3]],[4]) # returns None

Why does it return None instead of [[1],[2],[3],[4]] which I expected?
The answer is both "because that's what it's documented to do":

s.append(x) same as s[len(s):len(s)] = [x]
<URL:http://docs.python.org/lib/typesseq-mutable.html>

and "because you asked it to *do* something, not *get* something":

<URL:http://www.python.org/doc/faq/general.html#wh y-doesn-t-list-sort-return-the-sorted-list>

--
\ "There was a point to this story, but it has temporarily |
`\ escaped the chronicler's mind." -- Douglas Adams |
_o__) |
Ben Finney

Dec 21 '06 #5
On Thu, 21 Dec 2006 16:29:01 +1100, Ben Finney wrote:
Pyenos <py****@pyenos. orgwrites:
>def enlargetable(ta ble,col):
return table.append(co l)

def removecolfromta ble(table,col):
return table.remove(co l)

print enlargetable([[1],[2],[3]],[4]) # returns None

Why does it return None instead of [[1],[2],[3],[4]] which I expected?

The answer is both "because that's what it's documented to do":
Documentation is a funny thing...

help([].append)

Help on built-in function append:

append(...)
L.append(object ) -- append object to end

Sometimes it is hard to tell when you've read enough documentation.
However, as a general rule, "None whatsoever" is rarely enough.

--
Steven

Dec 21 '06 #6
i rewrote the code following the advices from subdir of the parent thread:

# well, table is composed of a list of columns.
# so let's stick them together
def enlargetable(ta ble,col):
table.append(co l) # the code won't return sorted lists :-o
return_the_fuck ing_table_bitch =table # assign it to a new variable to return it
return return_the_fuck ing_table_bitch # :-|
def removecolfromta ble(table,col):
return table.remove(co l)

print enlargetable([[1],[2],[3]],[4])

# and this code works.
Dec 21 '06 #7
Pyenos schrieb:
i rewrote the code following the advices from subdir of the parent thread:

# well, table is composed of a list of columns.
# so let's stick them together
def enlargetable(ta ble,col):
table.append(co l) # the code won't return sorted lists :-o
Why should it sort the list?
return_the_fuck ing_table_bitch =table # assign it to a new variable to return it
return return_the_fuck ing_table_bitch # :-|
That isn't necessary. A simple "return table" is fine.
>
def removecolfromta ble(table,col):
return table.remove(co l)
table.remove() also returns None.
print enlargetable([[1],[2],[3]],[4])

# and this code works.
Georg
Dec 21 '06 #8

Pyenos wrote:
def enlargetable(ta ble,col):
table.append(co l) # the code won't return sorted lists :-o
return_the_fuck ing_table_bitch =table # assign it to a new variable to return it
return return_the_fuck ing_table_bitch # :-|
Maybe you were just trying to be funny, but assiging the table to
another variable before returning is not only unnecessary, it
accomplishes nothing. The following will do exactly the same thing as
the above:

Expand|Select|Wrap|Line Numbers
  1. def enlargetable(table,col):
  2. table.append(col)
  3. return table
  4.  
Dec 21 '06 #9
At Thursday 21/12/2006 14:50, Matimus wrote:
>The following will do exactly the same thing as
the above:

Expand|Select|Wrap|Line Numbers
  1. def enlargetable(table,col):
  2.     table.append(col)
  3.     return table
Which, by the way, was one of the first answers he got, by Edward Kozlowski.
--
Gabriel Genellina
Softlab SRL


_______________ _______________ _______________ _____
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Dec 22 '06 #10

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

Similar topics

9
1608
by: Jakle | last post by:
I'm trying to write a program (with my very limited knowledge of python) that will convert text I type into those letters drawn with ascii symbols. I did 2 letters then went to test it. Here's the code I have so far: ******************************************* def S(): print " ________ " print " /--------\ " print "// ...
4
1929
by: Klaus Neuner | last post by:
Hello, the function given below returns all indexes of list2 where a sublist of list2 that is identical to list1 begins. As I will need this function quite often, I would like to know if more experienced programmers would agree with the way I defined the function: - Is there a more efficient way to do it? (Apart from building
4
1308
by: Bill | last post by:
I am trying to do an exercise in an online tutorial that but the tutorial does not list the solution. Could someone please tell me why the "hireCrew" method in the following code leaves me with a list that contains "None"? Be nice, this is my first go at this, thanks! class Organization: def __init__(self, argName, argLeader, argCrew):...
6
1510
by: M. Clift | last post by:
Hi All, I have tried to come up with a way to do this myself and all I end up with is very long code. What I have is a say item1, item4, item2, item1 etc... What I want to do is append to each item an extra value depending on the previous item.
30
3288
by: Raymond Hettinger | last post by:
Proposal -------- I am gathering data to evaluate a request for an alternate version of itertools.izip() with a None fill-in feature like that for the built-in map() function: >>> map(None, 'abc', '12345') # demonstrate map's None fill-in feature The motivation is to provide a means for looping over all data elements
5
1667
by: randomtalk | last post by:
hello, recently i tried to use list.append() function in seemingly logical ways, however, i cannot get it to work, here is the test code: >>> seed = >>> next = 7 >>> seed1 = seed.append(next) >>> seed1 >>> print(str(seed1)) None >>> def test(lst):
4
5748
by: pmacdiddie | last post by:
I have an append query that needs to run every time a line item is added to a subform. The append writes to a table that is the source for a pull down box. Problem is that it takes 5 seconds to run. This makes adding lines to an order too slow for the users. The result of the query provides real time availabilty, so I really do need this...
7
1644
by: Tobiah | last post by:
I wanted to do: query = "query text" % tuple(rec.append(extra)) but the append() method returns none, so I did this: fields = rec fields.append(extra) query = "query text" % tuple(fields)
42
1755
by: Armin | last post by:
Hi, just a dumb question. Let a = Why is the value of a.append(7) equal None and not ?? --Armin
0
8125
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8290
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7874
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6522
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5664
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3798
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2292
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 we have to send another system
1
1389
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1113
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.