Arrays vs Lists

Arrays vs Lists

Arrays vs Lists. Also lists are containers for elements having differing data types but arrays are used as containers for elements of the same data type.

In my beginning days of programming, I had the amazing idea that I should learn Java in order to make it easier for me to learn JavaScript. Obviously, this was wrong. Fast forward 2 years, I saw someone ask what the differences between Java and JavaScript was. The answer: “It’s like car and carpet.” You can find the question here. Fortunately, lists and arrays hold a much closer and less complicated relationship. Let’s begin.

Similarities

Python has built in lists, but it lacks arrays. In order to work with arrays, you have to use a library. I prefer to use Numpy. Let’s create an empty list and an empty array.

import numpy as np

lst = []
array = np.array([])

You may be thinking, “You misspelled list”. However, the word list is a python keyword, so it is not appropriate to use it. Since python does not have an array keyword there is no issues there. Both lists and arrays work similar, let’s look at the following example.

lst.extend([1,2,3,4,5,'six'])
array = np.append(array,[1,2,3,4,5,'six'])

lst.remove('six')
array = np.delete(array,-1)
lst.append(6)
array = np.append(array,6)

ai python data-structures machine-learning data-science

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.