Python Forum
Are lists Python's name for "variable array"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Are lists Python's name for "variable array"
#1
I'm working my way through the Eric Matthes book on Python and I've encountered his discussion of lists.  For example, code:

motorcycles = ['honda', 'yamaha', 'suzuki']
I used variable arrays a ton in Visual BASIC.  They were useful for storing messages in different languages.  For example, the 0 index was always English, 1 was French, 2 German, etc.  I used a lot of string variable arrays and integers, though there were others. 

So far it seems like I could use a list for exactly the same thing that I used to use variable arrays for.  

Are Python lists essentially the same thing or am I going to encounter variable arrays at some point?
Reply
#2
All languages have arrays or a method of carrying out the same procedure. But in python you could consider the list as python's array. However there is numpy.array which can be used for large amount of data.
Recommended Tutorials:
Reply
#3
Okay, thanks. So far it's been fascinating learning this new language.
Reply
#4
You can use lists as arrays, but they are actually much more than that.  For one thing, they can hold objects of different data types in a single list.  The important thing to remember is that their members are full-fledged objects, not just variables.
And of course, that implies all the overhead and slow performance that its flexibility implies.  As metulburr says, if you want real high-performing arrays, numpy is the way to go.
Reply
#5
(Apr-21-2017, 02:21 AM)llanitedave Wrote: You can use lists as arrays, but they are actually much more than that.  For one thing, they can hold objects of different data types in a single list.  The important thing to remember is that their members are full-fledged objects, not just variables.
And of course, that implies all the overhead and slow performance that its flexibility implies.  As metulburr says, if you want real high-performing arrays, numpy is the way to go.

Thanks.  I appreciate your taking the time to explain that.  I'm looking forward to becoming skilled in Python.  I want to re-write some utilities that I wrote in VB years ago and this time be able to have both Windows and Linux versions of them.  I'm working my way through the Eric Matthes book on Python.  Seems to be pretty well written.  I'll keep learning and getting better. 

I'm grateful for everyone's help.
Reply
#6
Unlike arrays in the most of the languages, a list in Python can hold arbitrary data types or objects.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#7
(Apr-21-2017, 12:12 AM)metulburr Wrote: However there is numpy.array which can be used for large amount of data.

There is also simply (seldom used) array, which is more or less in style of C arrays - with limitation to numeric types only.
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Turn list of arrays into an array of lists Cola_Reb 6 1,708 Jul-20-2022, 06:55 PM
Last Post: Cola_Reb
  Array lists vs Linked Lists sabe 2 1,763 Nov-28-2020, 12:31 AM
Last Post: perfringo
  Calculate the mean of an array across dimension with lists of different length rakhmadiev 2 4,521 Aug-01-2017, 02:52 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020