Arrays and Lists in Python




Data Structures are fundamental tools and concepts for any programmer. Python has a number of important Data Structures such as List, Tuples and Dictionary. Today I feel obliged to share something about Arrays and Lists in python. In Python, there are no  native array data structure, but it has a more generalised data structure that can serve the purpose of arrays called List. List can also be implemented as a multidimensional array.

This article basically entails the difference between arrays and lists and how we can used list as arrys in python. Advanced libraries in Python such as NumPy, Scikit-learn, Matplotlib.
 
  Image result for lists in python photo

 basics of lists

A list in Python is just an ordered collection of items which can be of any type. By comparison an array is an ordered collection of items of a single type - so in principle a list is more flexible than an array
To define a list you simply write a comma separated list of items in square brackets:
 
fruits=[banana,orange,pineapple, mango, apple]
 

print fruits[2]
will display the third element, i.e. the value mango in this case.
Similarly to change the third element you can assign directly to it:
fruits[2]=peas
The slicing notation looks like array indexing but it is a lot more flexible. For example
fruits[2:5]
is a sublist from the third element to the fifth i.e. from fruits[2] to fruits[4]. note that the final element specified i.e. [5] is not included in the slice.

Comments

Popular posts from this blog

Is Your Laptop or Desktop Safe from Hacking?

How to run a Java program on a Commandline

Nano Robots developed to fight and destroy Tumors