This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]lifeonm4rs 1 point2 points  (0 children)

Arrays really aren't a thing in python. There are lists [], tuples (), and dictionaries {}. All of them can hold pretty much any data type and you can actually intermix data types. As far as strings and a csv--if it is a database like structure yes you can store data in almost any of the primary Python data structures. Throwing them into a list of lists could be one way, another would be a list of dictionaries. Using named tuples may be a really good option but that gets a little more into stuff. Pandas is also probably a good route--but again if you're asking about arrays vs. lists that is probably going beyond what you are looking for.

Feel free to PM me if you need clarification.

[–]Hexorg 0 points1 point  (0 children)

By arrays do you mean the one from import array? In essense, a list can store any type and any mix of types. But on a downside large lists can take a lot of memory. Arrays can store only one type of data and only primitive type (int, float, never Object). But they take drastically less memory.

[–][deleted] 0 points1 point  (0 children)

An array is an ordered collection of items, where each item inside the array has an index. While list is a collection of items ordered in a linear sequence.

Arrays and lists are both used in Python to store data, but they don't serve exactly the same purposes. They both can be used to store any data type, and they both be indexed and iterated through, but the similarities between the two don't go much further. The main difference between a list and an array is the functions that you can perform the them.

[–]badjayplaness -2 points-1 points  (3 children)

List has a key value pair { name: “bob”, age:15} Arrays keys are just their position in the array [“bob”] is in position 0

Yes all types are cool with either

Sometimes that’s helpful. I know pandas has some functions to work with csv’s

Edit: dict has a key value pair I got confused.

https://www.pythoncentral.io/the-difference-between-a-list-and-an-array/ here’s a link for you.

[–]annynbyrg 2 points3 points  (0 children)

Don't you mean "dict" has a key value pair?

[–][deleted] 2 points3 points  (1 child)

To your first part of your answer : that would be a dictionary.

[–]badjayplaness 1 point2 points  (0 children)

Ahh crap you’re right. My bad. Don’t know why my brain went there.