In: Computer Science
Create a program (or set of programs) which accomplish the following for each complex data type (list,tuple,set,frozenset, dictionary):
And do the following:
Turn in:
PYTHON.
List
list.append() - used to insert element and another data structure at the end of list.
list.insert() - used to insert element at the particular index.
list.extend() - iterate over the list or string which we want to insert in list and insert it into the list.
list.remove() - remove that element from the list.
list.clear() - remove all the element from the list.
Here are the program in jupyter notebook :
Tuple
Tuple is immutable that means we cannot modify element in tuples.
Tuple elements are unchanged.
insert, remove and insert at particular index does work with tuple data structure.
Set
Set contains only unique element.
Set are unordered so we cannot add element at any index.
Set are written with {} curly bracket and set() function.
programs are given below for better understanding :
FrozenSet
Frozenset are the immutable version of set.
we cannot change, modify and remove element from frozenset. so any function like insert, delete and remove will not work with frozenset.
programs are below for better understanding :
Dictionary in python
Dictionary contains key value pair
Dictionary are unordered so insert at particular index is not possible.
Dictionary contains following functions like pop - to remove element, len - to find the length , clear - to remove all element, get - to get the particular function
programs are given below for better understanding :
2nd Part of Question
1. to create a range of negative numbers :
for creating range of negative number we use range function:
2. for creating positive even number we again use range function:
3. Insert range of element in data structure
Here I am showing only list and set because tuple and frozenset are immutable.