1

I cannot believe that this doesn't work. I guess I am missing something fundamental. I am trying to make a list of tuples:

newtags = []
print newtags
newtags = newtags.append(('{','JJ'))
print newtags

output is:

[]
None

I should be getting a list of tuples instead.

Brana
  • 1,197
  • 3
  • 17
  • 38

2 Answers2

3

.append() doesn't return anything. Your code will work fine if you remove the preceding newtags =:

newtags = []
print newtags
newtags.append(('{','JJ'))
print new tags

Which now runs as:

[]
[('{', 'JJ')]

Here's another example:

>>> arr = []
>>> print arr.append(9)
None
>>> arr
[9]
>>> arr = arr.append(8)
>>> arr
>>> print arr
None
>>> 
ZenOfPython
  • 891
  • 6
  • 15
1

The method append() modifies the list in-line. So, it doesn't return anything (i.e. returns None):

newtags = []
newtags.append(('{','JJ'))
Christian Tapia
  • 33,620
  • 7
  • 56
  • 73