473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

array and list

what's the difference between an array and a list in python?
I see list has all features of array in C or perl.
so please tell me.thanks.
Jan 18 '08 #1
10 11180
"J. Peng" <pe******@gmail.comwrites:
what's the difference between an array and a list in python?
In Python, 'list' is a basic built-in type. Python has no 'array'
type, though that term is often used to refer to the 'array' type
defined in Numeric Python (which is not part of the standard library,
so not really part of Python).
I see list has all features of array in C or perl.
You may also want to compare and constrast Python 'list' and 'dict'.

--
\ "When cryptography is outlawed, bayl bhgynjf jvyy unir |
`\ cevinpl." -- Anonymous |
_o__) |
Ben Finney
Jan 18 '08 #2
On Fri, 18 Jan 2008 15:05:23 +1100, Ben Finney wrote:
"J. Peng" <pe******@gmail.comwrites:
>what's the difference between an array and a list in python?

In Python, 'list' is a basic built-in type. Python has no 'array' type,
though that term is often used to refer to the 'array' type defined in
Numeric Python (which is not part of the standard library, so not really
part of Python).

Did you forget the array module?

>>import array
array
<module 'array' from '/usr/lib/python2.5/lib-dynload/arraymodule.so'>

>I see list has all features of array in C or perl.

You may also want to compare and constrast Python 'list' and 'dict'.
The Original Poster might also like to check out the help() and dir()
functions in the interactive interpreter:

help(list)
dir(list)
help(array)
help(array.array)

etc.


--
Steven
Jan 18 '08 #3
On Jan 18, 3:23 am, "J. Peng" <peng....@gmail.comwrote:
what's the difference between an array and a list in python?
I see list has all features of array in C or perl.
so please tell me.thanks.
If you are new to Python, then where other languages may reach for an
'array', Python programs might organise data as lists. Lists are used
much more than arrays in Python. you should find that is the case in
tutorials/books too.

P.S. if you know Perl then try: http://wiki.python.org/moin/PerlPhra...ght=%28perl%29
- Paddy.
Jan 18 '08 #4
Steven D'Aprano <st***@REMOVE-THIS-cybersource.com.auwrites:
On Fri, 18 Jan 2008 15:05:23 +1100, Ben Finney wrote:
In Python, 'list' is a basic built-in type. Python has no 'array'
type [...]
Did you forget the array module?
Yes.

--
\ "Always code as if the guy who ends up maintaining your code |
`\ will be a violent psychopath who knows where you live." —John |
_o__) F. Woods |
Ben Finney
Jan 18 '08 #5
On Jan 18, 3:23 am, "J. Peng" <peng....@gmail.comwrote:
>what's the difference between an array and a list in python?
I see list has all features of array in C or perl.
so please tell me.thanks.

If you are new to Python, then where other languages may reach for an
'array', Python programs might organise data as lists. Lists are used
much more than arrays in Python. you should find that is the case in
tutorials/books too.

http://wiki.python.org/moin/PerlPhra...ght=%28perl%29
- Paddy.
Hi,

From Core Python Programming book (btw I like this book) I know the
difference is that array can hold only one type (the C standard?), but
list can hold every type of object. But hmm, perl's array also can hold
every type of variables, why perl call it array and python call it list?
Also, if I understand it correctly, python's tuple is called as 'list'
in perl, so I'm somewhat confused about them.
P.S. if you know Perl then try:
Yes I know some Perl. I have registered module on CPAN.

thanks!

Jan 18 '08 #6
On Jan 18, 8:18 am, "J. Peng" <jp...@block.duxieweb.comwrote:
On Jan 18, 3:23 am, "J. Peng" <peng....@gmail.comwrote:
what's the difference between an array and a list in python?
I see list has all features of array in C or perl.
so please tell me.thanks.
If you are new to Python, then where other languages may reach for an
'array', Python programs might organise data as lists. Lists are used
much more than arrays in Python. you should find that is the case in
tutorials/books too.
http://wiki.python.org/moin/PerlPhra...ght=%28perl%29
- Paddy.

Hi,

From Core Python Programming book (btw I like this book) I know the
difference is that array can hold only one type (the C standard?), but
list can hold every type of object. But hmm, perl's array also can hold
every type of variables, why perl call it array and python call it list?
Similar ideas, different names. It happens. I guess 'under the hood'
Python
(& Perl?), arrays might be more like an implementation of what the C
programmer might call a linked list, but even then there are
differences as
most linked list examples given in C tutorials are lists of the same
type of
object,....

- Paddy.
Also, if I understand it correctly, python's tuple is called as 'list'
in perl, so I'm somewhat confused about them.
P.S. if you know Perl then try:

Yes I know some Perl. I have registered module on CPAN.

thanks!
Jan 18 '08 #7
J. Peng>why perl call it array and python call it list?<

Unfortunate naming, I'd say. Calling list a dynamic array is silly,
despite all the things you may say about abstract data types having
the correct methods, etc.
Paddy:
I guess 'under the hood' Python (& Perl?), arrays might be more like
an implementation of what the C programmer might call a linked list,
but even then there are differences as most linked list examples
given in C tutorials are lists of the same type of object,....
Both Python "array.array" and "list" are implemented as dyn arrays,
not as lists. Only the good "deque" by Hettinger is something similar
to a list (of small arrays).

Bye,
bearophile
Jan 18 '08 #8
Paddy:
I guess 'under the hood' Python (& Perl?), arrays might be more like
an implementation of what the C programmer might call a linked list,
but even then there are differences as most linked list examples
given in C tutorials are lists of the same type of object,....

Both Python "array.array" and "list" are implemented as dyn arrays,
not as lists. Only the good "deque" by Hettinger is something similar
to a list (of small arrays).

Bye,
bearophile
Ta!
Jan 18 '08 #9


On Jan 18, 2008, at 2:48 AM, be************@lycos.com wrote:
J. Peng>why perl call it array and python call it list?<

Unfortunate naming, I'd say. Calling list a dynamic array is silly,
despite all the things you may say about abstract data types having
the correct methods, etc.

I wouldn't call it unfortunate. The list semantics follow LISP's
semantics far more closely than C's array semantics. I would hazard
to guess that they are called lists because that is what every
functional language calls them and this aspect of python was modeled
after functional languages.

tj

Travis Jensen
tr***********@gmail.com

http://softwaremaven.innerbrane.com/

You should read my blog; it is more interesting than my signiature.

Jan 18 '08 #10
Travis Jensen <tr***********@gmail.comwrites:
I wouldn't call it unfortunate. The list semantics follow LISP's
semantics far more closely than C's array semantics. I would hazard
to guess that they are called lists because that is what every
functional language calls them and this aspect of python was modeled
after functional languages.
1. I don't think python was modelled after functional languages--it has
always been imperative, while slowly gaining functional features,
sometimes against opposition.

2. In functional langagues, "list" traditionally means a linked
structure while "array" is a linear structure, so python's use of
the term "list" is actually a little bit confusing.
Jan 18 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jonny | last post by:
Hey I need to search an array list to remove duplicate Data The list is populated by a search function that enters in a name if the it is told too This causes duplicate names to be entered...
1
by: Phenix Smith | last post by:
I am looking at coverting an application over to C#. Currently I have a global list varible that needs to be converted. I have tested different ideas to accomplish the same idea. Ths best way I...
13
by: Hrvoje Voda | last post by:
How to put a specified dataset table into an array list ? Hrcko
11
by: Zorpiedoman | last post by:
The problem is this: I have a list box. I set an array list as the datasource. I remove an item from the array list. I set the listbox datasource to nothing. I set the listbox datasource to...
18
by: Doug Bell | last post by:
Hi, I have a function that loads Rows from a field in a DataTable into an ArrayList. See below: It also adds a Row (eg "All Areas"). I wanted this new row to be the first record so I added a...
3
by: Ant | last post by:
Hi, I'm using an array list as the collection for my indexer (_alPeople). When i try to set _alpeople to a value at a certain index, I get an error. I can't simply add the value as it needs to be...
10
by: shanmukhi | last post by:
hi, how can i attach an iterator to array list and how can i get objects from database into that array list and how can i display that data on browser.... can any one help me........
2
by: hannahs | last post by:
I'll try to explain this the best I can. I have a class called book which creates books that each hold information such as author, title, ISBN code, etc. Then I have another class called...
22
by: Energizer100 | last post by:
Hey. I'm having some difficulty in Array lists. I have to find the average of all the numbers in an array list. That's my first task. My second one is to find the mode of all the numbers, meaning the...
3
dlite922
by: dlite922 | last post by:
I have a list of objects, the object has a String and an Int in it. I need to check to see if an item is in the list, if so increment the integer and save it back to the list. I believe I've done...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.