From Book Review to the Canonization of Literature

This is a slightly different version than the previously published in Beritagar, on Monday July 22, 2018, Dari Ulasan Buku ke Kanonisasi Sastra. The opinions expressed in this article are the…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




DATA STRUCTURES IN PYTHON

Data Structures are a way of organizing data so that it can be accessed more efficiently depending upon the situation. Data Structures are fundamentals of any programming language around which a program is built. Python helps to learn the fundamental of these data structures in a simpler way as compared to other programming languages.

There are mainly four data structures in python. They are,

=>LIST

=>TUPLE

=>DICTIONARY

=>SET

Indexing of the elements starts from ‘0’ (left to right) and ‘-1’(right to left). For example, if a list has ’n’ elements, then it’s index value ranges from “ 0 to n-1"

list declaration and indexing

For selecting several values of the same list,

In the above given example, list1[0:3], the first value indicates the starting element and the other value(say ‘n’)indicates the element positioned in n-1.

List consists of various number of methods which can be used to retrieve or access the stored data in the list. Some of the methods are append(), pop(), remove(), insert(), count(), extend(), reverse(), sort(), clear(), and much more.

Append()

Append is generally used to add elements into the list. Generally it adds the element to the end of a list.

Pop( )

Pop is used to remove an element from the list. Pop() removes the last element in the list. If you want to remove a specific element, it can be done by specifying its index.

Remove()

The remove() method is used to remove the elements by specifying its actual value.

Insert()

Insert() is used to insert the elements into the list in the specified index.

Here the first value specifies the index, and the second value specifies the object’s value.

Count()

It is used to count the number of occurence of the specified value.

Extend()

Extend() can be used if you want to insert several values at the same time.

Inserting a list into another list is called as Nested list. Here an entire list will be considered as a single element for a list.

The values of the list inside the nested list can be accessed by,

Index()

It is used to find the index value of the elements in the list

Reverse()

It is used to reverse the position of the elements in the list.

Sort()

This method is used to sort the elements in the list. This method works only if all the elements in the list are numerical.

Clear()

It is used to empty the list.

Copy()

Copy() is used to copy the elements of one list into another list.

Tuple is an immutable array. Once declared, the elements can never be changed or altered. It is same as list expect for few conditions.

eg.

Tuple does not have many methods for alteration or addition because it is immutable. We can typecast a tuple into list, and a list into a tuple like,

Dictionary is a type data structures in which the elements are stored in terms of key-value pairs {key : value}. It is a mutable array. Here the indexing is done through keys. Duplicate keys cannot be allowed.

The values can be retrieved by usings the keys,

The dictionary data structure has some methods to find all the available keys, values and items.

In Set, the elements will not be in a particular order. Any duplicate values present in the Set will be eliminated.

Pop()

Here the pop() method will remove a random element from the set.

Remove()

It is used to remove a specific element from the set.

Set is not the widely used data structure. It can be used only if we need to use the specific functions of the set.

Add a comment

Related posts:

Bibit Vanili Di5Kon Tanaman Varigata Super Seller Tulungagung Terunggul

bibit vanili di5kon tanaman varigata super seller #bibitbuah #tanamanbuah #benihbibitbuah #bibittanamanbuah #bibittanaman Berikut ini adalah beberapa manfaat dari daun vanili : 1. Sebagai campuran…

Invest only what you can afford

Warren Buffett has been one of the most successful investors of all time with a net worth of almost US$ 70 billion. One of his most famous rule in investment “ Rule No. 1: Never lose money. Rule No…

Remote working and working remotely

I have been reading a few articles and annoucements this week as companies publish their plans on how teams will work in the future, whether that is remote working, changes to office layouts, or a…