Python lists vs. arrays: How similar are they?

  Рет қаралды 16,058

Python and Pandas with Reuven Lerner

Python and Pandas with Reuven Lerner

Күн бұрын

If you've come to Python from a language like Java, then you're used to using arrays. But in Python, we use "lists." Are they the same things, but with different names? Or are these completely different? In this video, I answer this question, which I got from Sam, a subscriber to my free, weekly "Better developers" newsletter (BetterDevelopersWeekly.com/). I also look at Python's "array" module, as well as NumPy arrays.

Пікірлер: 15
@Random_Art822
@Random_Art822 2 жыл бұрын
This man types faster than I can run
@ReuvenLerner
@ReuvenLerner 2 жыл бұрын
It's all thanks to my parents forcing me when I was in high school. I promise you, everyone can learn to touch type, and you can/should learn as soon as you can!
@symfoniatragic
@symfoniatragic 2 жыл бұрын
@@ReuvenLerner Absolutely amazing skill! I beg you for some hints! I have no idea how to learn such fast touch type, how and where to start.
@ReuvenLerner
@ReuvenLerner 2 жыл бұрын
@@symfoniatragic Thanks; I learned when I was in high school, and it was one of the best things I ever learned. I *hated* it when I had to learn, but I super appreciate it now. I'll try to do a video about tyouch typingn in the future!
@itsJustJayMusic
@itsJustJayMusic Жыл бұрын
Fully answered! but it's still weird when I think about it. Thanks anyways. great video
@ReuvenLerner
@ReuvenLerner Жыл бұрын
Glad you enjoyed!
@chillidog8726
@chillidog8726 2 жыл бұрын
that i mean arrays in Java or C are faster to iterate over when using primitive data types that is why Java has Int and Integer Object when building an Integer Object array its almost the same as python lists with set length. But when just using a primitive type Array the data will be stored in memory directly following each other and adding the size of your datatype to the array pointer will return the next data point for example Int64 add 64 to your pointer and there you have the pointer to the next element but with python you would have to dereference twice you increment the array pointer to get the pointer to your data. The way C implements this makes branch prediction really good because if you access one element of an Array you are likely to want to access all of them. So the CPU can just load all of them into Cache and provide access without having cache misses. Now python might do some stuff to mittigate this but over all its gonna be a little slower. That should also be the reason why Arrays in python are only implemented for primitive data types since otherwise lists and arrays seem to be the same.
@bertholdhollmann4450
@bertholdhollmann4450 4 жыл бұрын
I'd say the use case for python arrays is communicating with extension modules. If you want to pass a collection of say ints between the python code and the C code in an extension module the array.array structures allow this quite easily, because the data is already stored as a C array and can be used without complicated copying in the glue code.
@ReuvenLerner
@ReuvenLerner 4 жыл бұрын
That's a very good point! I haven't written extension modules in C or any other language, but I do remember reading/seeing that arrays make it easier to do that. Thanks for the comment!
@gratain
@gratain 4 жыл бұрын
That was exactly the reason why I have used python array as well
@AntonZap
@AntonZap 2 жыл бұрын
thanks!
@thinkingcitizen
@thinkingcitizen 4 ай бұрын
List: Array of Pointers (Memory addresses) to Primary Data array.Array: Array of Primary Data, where type is restricted at array object creation
@luzengyuan5326
@luzengyuan5326 9 ай бұрын
I used array so often in C code which is very different from list.
@ReuvenLerner
@ReuvenLerner 9 ай бұрын
Yes, they're very different -- but so many people don't realize it.
The "else" clause in Python "for" loops - what does it do?
6:04
Python and Pandas with Reuven Lerner
Рет қаралды 730
Python lists, sets, and tuples explained 🍍
15:06
Bro Code
Рет қаралды 254 М.
Gym belt !! 😂😂  @kauermotta
00:10
Tibo InShape
Рет қаралды 18 МЛН
A teacher captured the cutest moment at the nursery #shorts
00:33
Fabiosa Stories
Рет қаралды 56 МЛН
Comfortable 🤣 #comedy #funny
00:34
Micky Makeover
Рет қаралды 9 МЛН
A Python list versus a NumPy array
16:27
John Philip Jones
Рет қаралды 4,4 М.
Compiled Python is FAST
12:57
Doug Mercer
Рет қаралды 105 М.
Method chaining in Pandas
18:17
Python and Pandas with Reuven Lerner
Рет қаралды 1,9 М.
Functions vs Classes: When to Use Which and Why?
10:49
ArjanCodes
Рет қаралды 150 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 289 М.
What does Python's __init__ method do?
6:56
Python and Pandas with Reuven Lerner
Рет қаралды 32 М.
15 Python Libraries You Should Know About
14:54
ArjanCodes
Рет қаралды 379 М.
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,7 МЛН
Python 101: Learn the 5 Must-Know Concepts
20:00
Tech With Tim
Рет қаралды 1,1 МЛН
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
Rob Mulla
Рет қаралды 265 М.
Что делать если в телефон попала вода?
0:17
Лена Тропоцел
Рет қаралды 3,4 МЛН
ноутбуки от 7.900 в тг laptopshoptop
0:14
Ноутбуковая лавка
Рет қаралды 3,6 МЛН
Vision Pro наконец-то доработали! Но не Apple!
0:40
ÉЖИ АКСЁНОВ
Рет қаралды 525 М.
Какой ноутбук взять для учёбы? #msi #rtx4090 #laptop #юмор #игровой #apple #shorts
0:18