Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Python Notes

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Python Important Topics

Lists: are just like dynamic sized arrays, declared in other languages (vector in C+
+ and ArrayList in Java). Lists need not be homogeneous always which makes it the
most powerful tool in Python. unlike lists that are mutable.
Tuple: A Tuple is a collection of Python objects separated by commas. In some
ways, a tuple is similar to a list in terms of indexing, nested objects, and repetition
but a tuple is immutable(Cannot be changed).
Set: A Set is an unordered collection data type that is iterable, mutable, and has no
duplicate elements. Python’s set class represents the mathematical notion of a set.
Dictionary: in Python is an ordered (since Py 3.7) [unordered (Py 3.6 & prior)]
collection of data values, used to store data values like a map, which, unlike other
Data Types that hold only a single value as an element, Dictionary
holds key:value pair. Key-value is provided in the dictionary to make it more
optimized.

List, Tuple, Set, and Dictionary are the data structures in python that are used to
store and organize the data in an efficient manner.

List Tuple Set Dictionary

List is a non-
homogeneous Tuple is also a non- Set data structure
Dictionary is also a
data structure that homogeneous data is also non-
non-homogeneous
stores the structure that stores homogeneous
data structure
elements in single row and data structure but
which stores key
single row and multiple rows and stores in single
value pairs
multiple rows columns row
and columns

Tuple can be
List can be represented by Set can be Dictionary can be
represented by [ ] represented by { } represented by { }
()

List allows Set will not allow Dictionary doesn’t


Tuple allows
duplicate duplicate allow duplicate
duplicate elements
elements elements keys.

List can use Tuple can use nested Set can use nested Dictionary can use
nested among all among all among all nested among all

Example: [1, 2, 3, Example: (1, 2, 3, 4, Example: {1, 2, 3, Example: {1: “a”,


4, 5] 5) 4, 5} 2: “b”, 3: “c”, 4:
“d”, 5: “e”}

List can be Dictionary can be


Tuple can be created Set can be created
created created
using tuple() functio using set() functi
using list() functi using dict() functio
n. on
on n.

Set is mutable i.e


List is mutable i.e Tuple is immutable we can make any Dictionary is
we can make any i.e we can not make changes in set. mutable. But Keys
changes in list. any changes in tuple But elements are are not duplicated.
not duplicated.

Dictionary is
List is ordered Tuple is ordered Set is unordered ordered (Python 3.7
and above)

Creating an empty Creating an empty Creating a set Creating an empty


list Tuple a=set() dictionary
l=[] t=() b=set(a) d={}

Below is the program for implementation of List, tuple, set, and dictionary:

Applications of List, Set, Tuple, and Dictionary


List:
 Used in JSON format
 Useful for Array operations
 Used in Databases
Tuple:
 Used to insert records in the database through SQL query at a time.Ex: (1.’sravan’, 34).
(2.’geek’, 35)
 Used in parentheses checker
Set:
 Finding unique elements
 Join operations

Dictionary:
 Used to create a data frame with lists
 Used in JSON

Use Cases of Python


1.Python program to convert Set into Tuple and Tuple into Set
2.Python | Convert List of Dictionary to Tuple list
3.Python Program to find tuple indices from other tuple list
4.Python - Flatten tuple of List to tuple
5.Python - Convert Tuple Matrix to Tuple List
6.Python | Sort tuple list by Nth element of tuple
7.Python Program to Merge tuple list by overlapping mid tuple
8.Python - Convert Dictionary Value list to Dictionary List
9.Python | Dictionary to list of tuple conversion
10.Python | Convert list of tuple into dictionary

Python Scripting Examples


https://linuxhint.com/python_scripts_beginners_guide/
https://www.freecodecamp.org/news/python-code-examples-sample-script-
coding-tutorial-for-beginners/
https://www.fosslinux.com/46256/python-script-examples.htm

You might also like