[aklug] Re: Lists

From: Tim Johnson <tim@akwebsoft.com>
Date: Tue Jul 26 2011 - 12:17:02 AKDT

* Shane R. Spencer <shane@bogomip.com> [110726 09:24]:
> If I'm not mistaken. Python list/tuple objects have a length integer attribute that gets
> incremented/decremented as needed. Python lists are really well implemented as far as I'm
> concerned thanks to how it's indexed.. however they chew up a bit more memory.
  Python lists are _mutable_, tuples are not
  python strings can be operated on, but are immutable.
List example:
>>> l = [1,3,2,6,5]
>>> a = l.sort()
>>> l
[1, 2, 3, 5, 6]
>>> type(a)
type 'NoneType' ## type of return value
Note that I removed the '<>' from the line above for
you folks who might be using html-based emailers.
string example:
>>> name = 'tim johnson'
>>> name.upper()
'TIM JOHNSON'
>>> name
'tim johnson'
The value of symbol `name' is unchanged (immutable),
you can create a new string by assign a symbol to
the return value for upper()
__extremely__ basic. But the basics are important :)

* Shane R. Spencer <shane@bogomip.com> [110726 09:24]:
> incremented/decremented as needed.
# yes
>>> l
[1, 2, 3, 5, 6, 7]
>>> len(l)
6
>>> l.append(8)
>>> len(l)
7

> Python lists are really well implemented
I haven't done any performance tests on lists vs dictionaries -
it is really a bit like comparing apples and oranges -
I believe python dictionaries are implemented from C linked lists.

-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Tue Jul 26 12:17:02 2011

This archive was generated by hypermail 2.1.8 : Tue Jul 26 2011 - 12:17:02 AKDT