MT 3 Notes
MT 3 Notes
3 NOTES
DICTIONARY FUNCTIONS:
FUNC USE EXAMPLE
TION
get () Returns the value for a my_dict.get
key; returns None or a ("key", 0)
default value if key is
not found.
keys () Returns a view object my_dict.keys ()
containing all keys.
values Returns a view object my_dict.values
() containing all values. ()
items () Returns a view object my_dict.items ()
containing key-value
pairs as tuples.
pop () Removes and returns the my_dict.pop
value for a specified key. ("key")
popitem Removes and returns the my_dict.popite
() last inserted key-value m ()
pair.
clear () Removes all key-value my_dict.clear ()
pairs from the dictionary.
update Updates the dictionary my_dict.update
() with another dictionary ({"a": 1})
or key-value pairs.
copy () Returns a shallow copy n_dict =
of the dictionary. my_dict.copy ()
len () Returns the number of len (my_dict)
key-value pairs in the
dictionary.
del () Deletes a specified key del my_dict
from the dictionary. ["key"]
in Checks if a key exists in "key" in my_dict
the dictionary.
dict () Creates a dictionary dict ( [ ("a", 1),
from an iterable of key- ("b", 2) ] )
value pairs.
LIST FUNCTIONS:
FUNCT USE EXAMPLE
ION
append Adds an item to the end my_list.append
() of the list. (5)
extend () Adds elements to the my_list.extend
end of the list. ( [1, 2] )
insert () Inserts an item at a my_list.insert
specific index. (1, 5)
remove Removes the first my_list.remove
() occurrence of a (5)
specified value.
pop () Removes and returns my_list.pop (2)
an item at a specified
index.
clear () Removes all elements my_list.clear ()
from the list
index () Returns the index of my_list.index (5)
the first occurrence of a
specified value.
count () Returns the number of my_list.count (5)
occurrences of a
specified value.
sort () Sorts the list in my_list.sort ()
ascending order.
reverse Reverses the elements my_list.reverse
() of the list in place. ()
copy () Returns a shallow copy new_list =
of the list. my_list.copy ()
len () Returns the number of len (my_list)
elements in the list.
min () Returns the smallest min (my_list)
element in the list.
max () Returns the largest max (my_list)
element in the list.
sum () Returns the sum of all sum (my_list)
numeric elements.
sorted () Returns a new sorted sorted (my_list)
list without modifying
the original list.
list () Converts an iterable list ( (1, 2, 3) )
into a list.
Language Translators:
Used to convert assembly or high –
level language [ Source Code ] to
machine language [ Object / Machine
Code ] for computer system to proceed
Assembler: Converts assembly
language [ Low – level ] to machine
language
Compiler: Converts high – level
programming language [ Source
Code ] to Machine code
Interpreter: Converts High – level
programming language line by line
into machine code
Truth Table:
Represents all the possible values of
logical variables or statements
along with all the possible results of
the given combinations of values
A truth table of “n” input variables
have 2n input combinations
De Morgan’s Law:
Involution Law:
((X)’)’ = X
Decimal Binary Octal ( Hexadecim
( )10 ( )2 )8 al ( )16
0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Rules for Number system conversion:
1. Decimal to any number system:
Repeated division by the base
needed
2. Any number system to decimal:
Positional value method
3. Octal & Hexadecimal number
systems to Binary: Relation
Table
4. Octal to Hexadecimal & Vice
versa: Convert to binary then to
required number system
5. Octal – 3 bits of binary,
Hexadecimal – 4 bits of binary
Shallow Copy:
Doesn’t change element if changed in
OG list or tuple or dict
1. Copy ()
2. Slicing
3. List ()
4. dict ()
5. tuple ()
Deep Copy:
Changes the element if changed in OG
list or tuple or dict
1. =