append

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • HMS Surprise

    #1

    append

    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

  • HMS Surprise

    #2
    Re: append

    Found list popping at

    http://en.wikibooks.org/wiki/Python_Programming/Lists :)

    Comment

    • Carsten Haese

      #3
      Re: append

      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:



      HTH,

      --
      Carsten Haese



      Comment

      • Bill Pursell

        #4
        Re: append

        On 10 May, 18:02, HMS Surprise <j...@datavoice int.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().a ppend)

        Comment

        • jmg3000@gmail.com

          #5
          Re: append

          On May 10, 1:11 pm, HMS Surprise <j...@datavoice int.comwrote:You can find terse info on the list methods by doing:
          >>help(list)
          ---John

          Comment

          • Duncan Booth

            #6
            Re: append

            HMS Surprise <john@datavoice int.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

            Comment

            • Neil Cerutti

              #7
              Re: append

              On 2007-05-10, HMS Surprise <john@datavoice int.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

              Comment

              • HMS Surprise

                #8
                Re: append


                >
                Do you really mean syntax?
                >
                Thought so?

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

                Learn how to create, access, modify, and sort lists in Python. Add, remove, and copy items with ease. Start coding now!




                Thank you all.

                jh

                Comment

                • Terry Reedy

                  #9
                  Re: append


                  "Neil Cerutti" <horpner@yahoo. comwrote in message
                  news:slrnf46nud .1hg.horpner@FI AD06.norwich.ed u...
                  | On 2007-05-10, HMS Surprise <john@datavoice int.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

                  and section 2.1


                  A substantial number of newbie questions are answered therein.

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

                  tjr



                  Comment

                  • Bruno Desthuilliers

                    #10
                    Re: append

                    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)

                    Comment

                    • vdicarlo

                      #11
                      Re: append

                      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



                      Full text searches (not limited to keywords like the resource above)
                      of the Python Library Reference can also be done at


                      Other handy references are:

                      Dive into Python at
                      Explore the power of Python in the 2026: see our free tutorials and obtain the "Dive into Python" book by Mark Pilgrim in PDF and Kindle version.


                      The Python 2.5 Quick Reference at
                      Python 2.5 language Quick Reference, freely available in HTML (several styles) and PDF versions.


                      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.

                      Comment

                      • Colin J. Williams

                        #12
                        Re: append

                        Sick Monkey wrote:

                        >
                        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(33 3)
                        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* <john@datavoice int.com
                        <mailto:john@da tavoiceint.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
                        >
                        --

                        >
                        >
                        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.

                        Comment

                        • Colin J. Williams

                          #13
                          Re: append

                          Sick Monkey wrote:

                          >
                          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(33 3)
                          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* <john@datavoice int.com
                          <mailto:john@da tavoiceint.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
                          >
                          --

                          >
                          >
                          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.

                          Comment

                          • James T. Dennis

                            #14
                            Re: append

                            Bruno Desthuilliers <bdesth.quelque chose@free.quel quepart.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("f oo")) 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_descript or
                            Base Class: <type 'method_descrip tor'>
                            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.rea dline.parse_and _bind("tab: complete")

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

                            rlcompleter.rea dline.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

                            Comment

                            Working...