473,666 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11217
"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.arra y)

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.du xieweb.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.arra y" 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.arra y" 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***********@g mail.com

http://softwaremaven.innerbrane.com/

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

Jan 18 '08 #10

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

Similar topics

4
4469
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 into the array, the search function is not changable e. the array list has 5 values "jonny", I need to remove all the values but the 1st. The array can have several differnet copies of one name
1
6069
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 have found for me is to create a configuration class with a static array list that is accessed through static methods. Is there a better way to handle this. This class is in a DLL if that makes a difference. public class Configuration {...
13
11304
by: Hrvoje Voda | last post by:
How to put a specified dataset table into an array list ? Hrcko
11
8548
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 the array list again to refresh. Click on an item in the list, and an Indexing error comes up. (in non-user code, it is trying to get an element from the array that is greater than the number of items in the array.) To reproduce:
18
1757
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 preceeding space (eg " All Areas") and sorted the ArrayList. I have just found that there are some valid records that have one or more
3
3570
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 at an index set by the user. the Set statement is this: _people = value; or even _people.Insert(index,value); but these throw 'ArgumentOutOfRange' exception stating: Must be non-negative and less than the size of the collection.
10
3245
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
1605
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 booklist which stores the books in an array list. In the booklist class I am trying to write a method which will determine whether or not any of the books have a certain ISBN code. I am having trouble figuring out how to start with an array list and...
22
5874
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 number that shows up the most. And the third one is to find a standard deviation, which I will get to later. Anyway, right now I'm doing Average. public class Statistics { public static void main(String args) { ArrayList <Integer>...
3
8783
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 everything OK up to the point of checking to see if an object is in the list by overloading the equals() and hashCode() functions. I don't have any errors and compiles except my list contains two entries of the same name (String) instead of...
0
8449
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8360
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8642
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4371
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2774
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1777
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.