By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,548 Members | 1,496 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,548 IT Pros & Developers. It's quick & easy.

append

P: n/a
Trying not to be a whiner but I sure have trouble finding syntax in
the reference material. I want to know about list operations such as
append. Is there a pop type function? I looked in tutorial, language
reference, and lib for list, append, sequence. Is there a place where
us doofi ( who may not have our heads out in the sunlight) may find
all related syntax grouped together?

thanx,

jh

May 10 '07 #1
Share this Question
Share on Google+
13 Replies


P: n/a

P: n/a
On Thu, 2007-05-10 at 10:02 -0700, HMS Surprise wrote:
Trying not to be a whiner but I sure have trouble finding syntax in
the reference material. I want to know about list operations such as
append. Is there a pop type function? I looked in tutorial, language
reference, and lib for list, append, sequence.
Have you tried Google? Searching for "python list append" brings up the
following useful looking link to the tutorial at the very top:

http://docs.python.org/tut/node7.html

HTH,

--
Carsten Haese
http://informixdb.sourceforge.net
May 10 '07 #3

P: n/a
On 10 May, 18:02, HMS Surprise <j...@datavoiceint.comwrote:
Trying not to be a whiner but I sure have trouble finding syntax in
the reference material. I want to know about list operations such as
append. Is there a pop type function? I looked in tutorial, language
reference, and lib for list, append, sequence. Is there a place where
us doofi ( who may not have our heads out in the sunlight) may find
all related syntax grouped together?
>>dir(list())
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
'__delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__',
'__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__',
'__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__',
'__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__',
'__setslice__', '__str__', 'append', 'count', 'extend', 'index',
'insert', 'pop', 'remove', 'reverse', 'sort']
This doesn't give syntax, but if you have any questions, try:
>>help(list().append)
May 10 '07 #4

P: n/a
On May 10, 1:11 pm, HMS Surprise <j...@datavoiceint.comwrote:
Found list popping at

http://en.wikibooks.org/wiki/Python_Programming/Lists:)
You can find terse info on the list methods by doing:
>>help(list)
---John

May 10 '07 #5

P: n/a
HMS Surprise <jo**@datavoiceint.comwrote:
Trying not to be a whiner but I sure have trouble finding syntax in
the reference material. I want to know about list operations such as
append. Is there a pop type function? I looked in tutorial, language
reference, and lib for list, append, sequence. Is there a place where
us doofi ( who may not have our heads out in the sunlight) may find
all related syntax grouped together?
Do you really mean syntax?

Anyway, try google: python list methods

The second result is: http://docs.python.org/lib/typesseq-mutable.html
May 10 '07 #6

P: n/a
On 2007-05-10, HMS Surprise <jo**@datavoiceint.comwrote:
Trying not to be a whiner but I sure have trouble finding
syntax in the reference material. I want to know about list
operations such as append. Is there a pop type function? I
looked in tutorial, language reference, and lib for list,
append, sequence. Is there a place where us doofi ( who may not
have our heads out in the sunlight) may find all related syntax
grouped together?
You need the material in the Python Manual in the astonishingly
useful Library Reference section 1.2.3: Built-In Types. The only
thing you'll look at nearly as much is 1.2.1: Built-In Functions.

--
Neil Cerutti
May 10 '07 #7

P: n/a

>
Do you really mean syntax?
Thought so?

A few sources I bookmarked to avoid future google two-steps.

http://www.diveintopython.org/native...pes/lists.html
http://en.wikibooks.org/wiki/Python_Programming/Lists
http://infohost.nmt.edu/tcc/help/pubs/python22.pdf

Thank you all.

jh

May 10 '07 #8

P: n/a

"Neil Cerutti" <ho*****@yahoo.comwrote in message
news:sl********************@FIAD06.norwich.edu...
| On 2007-05-10, HMS Surprise <jo**@datavoiceint.comwrote:
| Trying not to be a whiner but I sure have trouble finding
| syntax in the reference material. I want to know about list
| operations such as append. Is there a pop type function? I
| looked in tutorial, language reference, and lib for list,
| append, sequence. Is there a place where us doofi ( who may not
| have our heads out in the sunlight) may find all related syntax
| grouped together?
|
| You need the material in the Python Manual in the astonishingly
| useful Library Reference section 1.2.3: Built-In Types. The only
| thing you'll look at nearly as much is 1.2.1: Built-In Functions.

In the current version of the library reference, these are chapter 3
http://docs.python.org/lib/types.html
and section 2.1
http://docs.python.org/lib/built-in-funcs.html

A substantial number of newbie questions are answered therein.

'append' has several entries in the substantial lib ref index.

tjr

May 10 '07 #9

P: n/a
HMS Surprise a écrit :
Trying not to be a whiner but I sure have trouble finding syntax in
the reference material. I want to know about list operations such as
append.
The only thing you have to know is that it doesn't exists. Python
strings are immutables. If you want to sequentially build a string, you
can either rebind the name to a new string :

s = ""
for c in "abcdef":
s += c

or collect substrings in a list and join it:

s = []
for c in "abcdef":
s.append(c)
s = "".join(s)
May 10 '07 #10

P: n/a
the reference material. I want to know about list
>operations such as
append.
I've been struggling myself to assemble and learn just the right
combination of quick references. Here is some of what I've found.

For a quick search for the syntax and a simple example of a particular
method or function, the single most efficient source for me has been
the keyword search page for the Python Library Reference, Language
Reference, and Python/C API manuals that you can find from a link on
the official documentation page at http://www.python.org/doc/ or
directly at

http://starship.python.net/crew/theller/pyhelp.cgi

Full text searches (not limited to keywords like the resource above)
of the Python Library Reference can also be done at
http://www.zvon.org/other/python/PHP/search.php

Other handy references are:

Dive into Python at
http://diveintopython.org/toc/index.html

The Python 2.5 Quick Reference at
http://rgruet.free.fr/PQR25/PQR2.5.html

Last, but far from least, the one resource that I most wish I had
known about when I started with Python is the screencast tutorial site
at www.showmedo.com. There are two excellent free screencasts on
Python resources at http://tinyurl.com/2qkuht and lots of other Python
tutorials, most free and some for a modest fee. In particular, the 9th
installment of the paid series called Python Newbies on XP at
http://tinyurl.com/3ayhwt is about how to use the help functions built
into Python Idle.

May 11 '07 #11

P: n/a
Sick Monkey wrote:
http://docs.python.org/tut/node7.html

Yes there is a pop function.

"An example that uses most of the list methods:
>>>a = [66.25, 333, 333, 1, 1234.5]
print a.count(333), a.count(66.25), a.count('x')
2 1 0
>>>a.insert(2, -1)
a.append(333)
a
[66.25, 333, -1, 333, 1, 1234.5, 333]
>>>a.index(333)
1
>>>a.remove(333)
a
[66.25, -1, 333, 1, 1234.5, 333]
>>>a.reverse()
a
[333, 1234.5, 1, 333, -1, 66.25]
>>>a.sort()
a
[-1, 1, 66.25, 333, 333, 1234.5]

"
On 10 May 2007 10:02:26 -0700, *HMS Surprise* <jo**@datavoiceint.com
<mailto:jo**@datavoiceint.com>wrote:

Trying not to be a whiner but I sure have trouble finding syntax in
the reference material. I want to know about list operations such as
append. Is there a pop type function? I looked in tutorial, language
reference, and lib for list, append, sequence. Is there a place where
us doofi ( who may not have our heads out in the sunlight) may find
all related syntax grouped together?

thanx,

jh

--
http://mail.python.org/mailman/listinfo/python-list

Most of the syntax is set out in Sections 5, 6, 7 & 8 of the Language
Reference Manual, with a very small part in Section 2.

Colin W.

May 14 '07 #12

P: n/a
Sick Monkey wrote:
http://docs.python.org/tut/node7.html

Yes there is a pop function.

"An example that uses most of the list methods:
>>>a = [66.25, 333, 333, 1, 1234.5]
print a.count(333), a.count(66.25), a.count('x')
2 1 0
>>>a.insert(2, -1)
a.append(333)
a
[66.25, 333, -1, 333, 1, 1234.5, 333]
>>>a.index(333)
1
>>>a.remove(333)
a
[66.25, -1, 333, 1, 1234.5, 333]
>>>a.reverse()
a
[333, 1234.5, 1, 333, -1, 66.25]
>>>a.sort()
a
[-1, 1, 66.25, 333, 333, 1234.5]

"
On 10 May 2007 10:02:26 -0700, *HMS Surprise* <jo**@datavoiceint.com
<mailto:jo**@datavoiceint.com>wrote:

Trying not to be a whiner but I sure have trouble finding syntax in
the reference material. I want to know about list operations such as
append. Is there a pop type function? I looked in tutorial, language
reference, and lib for list, append, sequence. Is there a place where
us doofi ( who may not have our heads out in the sunlight) may find
all related syntax grouped together?

thanx,

jh

--
http://mail.python.org/mailman/listinfo/python-list

Most of the syntax is set out in Sections 5, 6, 7 & 8 of the Language
Reference Manual, with a very small part in Section 2.

Colin W.
May 14 '07 #13

P: n/a
Bruno Desthuilliers <bd*****************@free.quelquepart.frwrote:
HMS Surprise a ?crit :
>Trying not to be a whiner but I sure have trouble finding syntax in
the reference material. I want to know about list operations such as
append.
The only thing you have to know is that it doesn't exists. Python
strings are immutables. If you want to sequentially build a string, you
can either rebind the name to a new string :
Huh? Where did strings come into this question?
s = ""
for c in "abcdef":
s += c
Huh? Why not just use: s = list(s)? For a more clear example:
>>list("foo")
['f', 'o', 'o']

See?
or collect substrings in a list and join it:
s = []
for c in "abcdef":
s.append(c)
s = "".join(s)
Yes, "".join(list("foo")) is a sort of "expensive" no-op.

As for the original post: dir() and help() from the interactive
prompt are good friends. An ipython prompt is an even better
friend to have while learning python. Consider this:

In[1]:list.app[[Tab]] ...
list.append

In[1]:list.append[[?]][[Enter]]

Type: method_descriptor
Base Class: <type 'method_descriptor'>
String Form: <method 'append' of 'list' objects>
Namespace: Python builtin
Docstring:
L.append(object) -- append object to end

In[2]:

... where I'm highlighting some keystrokes with [[]] marks.

The point is that ipython offers [Tab] completion(*) and
has a number other cool features. For example if you end a
function/method/class/member line with a ? key and hit enter,
then you get a help screen as shown in my mini-transcript above.

Python simply has the best interactive introspection features
around. (Also, if you use docstrings in your own code than
these features will work on your code, too).

For extra fun go into one of your directories which contains
some of your .py files, and/or add a few such directories to
your PYTHONPATH environment variable. Then start up a command
like:

pydoc -p 8080

... or pick some other TCP port.

Then point a web browser at localhost:8080 ...

... see? There's a mini-web service with clickable links
to read the docs for all the Python modules installed on
your system ... including your own code!

* ([Tab]-completion is also possible in the normal python >>>
interpreter using: import rlcompleter
... and then calling the relatively obscure incantation:

rlcompleter.readline.parse_and_bind("tab: complete")

If, like me you prefer vi-mode readline editing then you
add another incantation:

rlcompleter.readline.parse_and_bind("set editing-mode vi")

... or you can simply put the following in you ~/.inputrc:

$if python
set editing-mode vi
$endif

... and, in that case, you can bind other keystrokes into macro
strings like: C-o:"import sys,os" or whatever).
--
Jim Dennis,
Starshine: Signed, Sealed, Delivered

May 25 '07 #14

This discussion thread is closed

Replies have been disabled for this discussion.