0% found this document useful (0 votes)
8 views17 pages

MT 3 Notes

The document provides an overview of various functions for dictionaries and lists in Python, including methods for retrieving, modifying, and managing data structures. It also covers concepts related to logic gates, truth tables, number system conversions, and character encoding standards like ASCII, ISCII, and Unicode. Additionally, it distinguishes between shallow and deep copies in data structures.

Uploaded by

orewairfan05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views17 pages

MT 3 Notes

The document provides an overview of various functions for dictionaries and lists in Python, including methods for retrieving, modifying, and managing data structures. It also covers concepts related to logic gates, truth tables, number system conversions, and character encoding standards like ASCII, ISCII, and Unicode. Additionally, it distinguishes between shallow and deep copies in data structures.

Uploaded by

orewairfan05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

COMPUTER SCIENCE MT

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

Binary Decision: Decision resulting in


Yes or No [ True or False ]

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

Tautology: If the result of any logical


statement or expression is
always True or 1 for all input
combinations
Fallacy: If the result of any logical
statement or expression is
always False or 0 for all input
combinations
Logic Gates:
1. AND gate [ * ]:
A B R
0 0 0
0 1 0
1 0 0
1 1 1
2. OR gate [ + ]:
A B R
0 0 0
0 1 1
1 0 1
1 1 1
3. NOT gate [ ` ]:
A R
0 1
1 0

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

American Standard Code For


Information Interchange [ ASCII ]:
 Introduced to standardize the
character representation
 Used 7 bits to represent characters

Indian Script Code For Information


Interchange [ ISCII ]:
 Introduced in order to facilitate the
use of Indian languages on the
computers
 Used 8 bits to represent characters

Universal Character Encoding Standard


[ UNICODE ]:
 Incorporates all the characters of
every written languages of the
world
setdefault() - returns the value of a
specified key & If the key doesn’t exist,
it inserts the key with the specified
default value and returns that default
value.

The fromkeys() function in Python is a


dictionary method used to create a new
dictionary with specified keys and a
common default value.

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. =

You might also like