CSE SKILL LAB 2
PRACTICAL 1
PRIYANKA SURYAWANSHI
STUDY AND IMPLEMENT DATA
STRUCTURES IN PYTHON
INTRODUCTION
• Python is a general purpose high level programming language.
• Python was developed by Guido Van Rossam in 1989 while working at National Research
Institute at Netherlands.
• But officially Python was made available to public in 1991. The official Date of Birth for
Python is : Feb 20th 1991.
• Python is recommended as first programming language for beginners.
HISTORY OF PYTHON
• The name Python was selected from the TV Show "The Complete Monty Python’s Circus",
which was broadcasted in BBC from 1969 to 1974.
• Guido developed Python language by taking almost all programming features from
different languages
1. Functional Programming Features from C
2. Object Oriented Programming Features from C++
3. Scripting Language Features from Perl and Shell Script
4. Modular Programming Features from Modula-3
Most of syntax in Python Derived from C and ABC languages.
APPLICATIONS OF PYTHON
• NOTE:
• Internally Google and Youtube
use Python coding
• NASA and Nework Stock
Exchange Applications developed
by Python.
• Top Software companies like
Google, Microsoft, IBM, Yahoo
using Python.
TOP COMPANIES USING PYTHON
FEATURES OF PYTHON
• General Purpose
• Dynamically typed
• Object Oriented
• High level
• Multilevel
• Interpretted
• Open Source
• Functional
• Procedural
FLAVORS OF PYTHON
PYTHON VERSIONS
• Python 1.0V introduced in Jan 1994
• Python 2.0V introduced in October 2000
• Python 3.0V introduced in December 2008
• NOTE
• Python 3 won't provide backward compatibility to Python2
• i.e there is no guarantee that Python2 programs will run in Python3.
INSTALLATIONS
1) Python Interpretter [Link]
• Current version 3.10.0
3 - -major version -- new functionality added which was not there prev
10 -- minor version -- extension to the existing functionality
0 -- patch number -- defect resolution
2) Pycharm (community edition - free)
IDE (Integrated Development Environment)... faster development
Widely used in companies.
DATA TYPES
• Simple Data types
• Complex Data types
Simple Data types (can hold one element at a time) –
1) Number
Int val = 10
Float val = 10.5
complex value val = 3273 + 4j
2) String ‘a ’ , “the “ , ‘’’ great ‘’’ , “””simple “””
3) Bool True/False
4) Nonetype None
Complex Data types (collection of elements- homogeneous or heterogeneous)
1) List []
2) Set {}
3) Tuples ()
4) Dict {key1:value1, key2:value2}
SIMPLE DATATYPES
• Number data type
1) int 3) Complex value
a=10
type(a) c = 10+1.5j
type(c)
2) float
Note: Some built in functions
b=7.3
type(b) type() - To check the type of variable
id() - To get the address of object
print() - To print the value
• String data type
String slicing
• Bool data type
COMPLEX DATA TYPES
List []
• List is mutable
• Duplicate allowed
• Sequence maintained
• Multiple None types are allowed
• Add/delete/update/replace allowed
• Growable in nature
• Array data structure is used
set {}
• Set is Mutable
• Duplicates not allowed
• Sequence not maintained
• Single None type is allowed only
• Hash table data structure
• Growable in nature
• Index concept is not applicable
Tuple ( )
• Immutable
• Duplicated allowed
• Sequence allowed
• Many none types allowed
• Array data structure used
Dictionary { }
• {pair} -- key:value
• Mutable
• hashtable + DLL
• Key
duplicates not allowed
seq maintained
single NoneType Allowed
• Value
duplicates Allowed
multiple NoneType allowed
seq - no question - value comes with key… sequence as per key
WHAT IS A DATA STRUCTURE?
• Organizing, managing and storing data is important as it enables easier access
and efficient modifications.
• Data Structures allows you to organize your data in such a way that enables you to
store collections of data, relate them and perform operations on them accordingly.
LIST
SET
TUPLE
DICTIONARY
PROBLEM STATEMENTS
1. Write a program to display unique vowels present in the given word? (list)
2. Write a program to take a tuple of numbers from the keyboard and print its sum and
average?
3. Write a program to eliminate duplicates present in the set?
4. Write a program to print different vowels present in the given word? (set)
5. Write a program to enter name and percentage marks in a dictionary and display
information on the screen
6. Write a program to take dictionary from the keyboard and print the sum of values?
7. Write a program to find number of occurrences of each letter present in the given string?
8. Write a program to accept student name and marks from the keyboard and creates a
dictionary. Also display student marks by taking student name as input?
9. Create a list by picking an odd index items from the first list and even index items from
the second
10. Remove and add item in the list
11. Slice list into 3 equal chunks and reverse each chunk
12. Create a Python set such that it shows the element from both lists in a pair
13. Find the intersection (common) of 2 sets and remove those elements from the first set.
14. Iterate a given list and check if a given element exists as a key’s value in a dictionary. If
not, delete it from the list.
15. Get all values from the dictionary and add them to a list but don’t add duplicates.