#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Posts
    8
    Rep Power
    0

    Point me in the right direction.


    I'm new to python and programming in general. I'm working on a program for a friend. Basically that would take inputed measurements take some deductions and some counts. My question is Is there a type of dynamic array for python? One that I could add to as the expressions are added as input from the keyboard.

    I haven't been able to get my mind around list, tuples and dictionaries. If you can suggest which is my best option I will take it from there. Thanks.
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Use the List, this is basically as you referred to it a "Dynamic Array". You can use the append() method to add elements to the list like so.

    Code:
    >>> aList = []
    >>> aList.append(0)
    >>> aList.append(True)
    >>> aList.append('String')
    >>> aList
    [0, True, 'String']
    >>> aList.append('String')
    >>> aList
    [0, True, 'String', 'String']
    >>>
    Also see:

    http://www.python.org/doc/2.4/lib/typesseq.html
    http://www.python.org/doc/2.4/tut/node5.html#SECTION005140000000000000000

    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Posts
    8
    Rep Power
    0

    yes definitely helped.


    I just need a hint (in enlish) thanks.
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    A List is a mutable array, this means that it can add new valued to it after its created. This is usually done by prefixing your list with .append(valueToAdd) as in the example above.

    A Tuple is pretty much the same but is immutable, so can't add values to it after it has been created.

    You probably wont use a dictionary for this but simply: Dictionaries are like arrays but they use keys (usually strings) to access the stored values rather than an index/number.

    Better?

    Mark .
    programming language development: www.netytan.com Hula

  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Posts
    8
    Rep Power
    0

    yes thanks


    I'm using a book by chris Fehily visual quickstart guide. The language is a little difficulf for this high school grad. haha thank you again my program is looking good now.

IMN logo majestic logo threadwatch logo seochat tools logo