<jupyter_start><jupyter_text>Date: 29 Sep 2021 Day: Wednesday  Lecture 03 Session 01  String Data Type<jupyter_code>x="One Attack"
print(x)
# strip space from left side
print(x.lstrip())
# strip spac from right side
print(x.rstrip())
# strip spca from both sides
print(x.strip())<jupyter_output>One Attack
One Attack
One Attack
One Attack<jupyter_text>Boolean Data Type1) There are only two values in boolean TRUE or FALSE  2) When you are writing True or False the first letter must be captial 3) You can use boolean with the if else statement 4) 0 Represent the False and 1 represent True  Truth Table<jupyter_code>True and True
True or False
False and True<jupyter_output><empty_output><jupyter_text>Class Exercise:  1.Number: 1.1 Operations with Numbers<jupyter_code>1+1
2**3
8%5
8.0//5.0<jupyter_output><empty_output><jupyter_text>2. String 2.1 Basic<jupyter_code>print("He said 'Python is very easy'")
print("He said 'Python is very Good'")
my_string= """Hello Name 
is
Rafay
and
My Brother
Name 
is 
Moeez 
and 
Muqeet"""
print(my_string)<jupyter_output>Hello Name 
is
Rafay
and
My Brother
Name 
is 
Moeez 
and 
Muqeet<jupyter_text>2.2 Operating with String<jupyter_code>str1 = 'First Meeting'
str2 = ' Second Meeting'
print(str1 + str2)
str1='Hello baby!!'
print(str1*5)<jupyter_output>Hello baby!!Hello baby!!Hello baby!!Hello baby!!Hello baby!!<jupyter_text>2.3: Indexing and Silicing String<jupyter_code>str1 = 'Life is too short,You need to learn Python!'
print(str1[0])
print(str1[3])
print(str1[0:4])
print(str1[5:1])<jupyter_output>L
e
Life<jupyter_text>2.4: Function and Methods for String objects<jupyter_code>x= 'Python'
# check the length of the string
print(len(x))
# counting the word that is asked by the user
x.count('h')
# to turn all CAPS into lower caps
x.lower()
# to turn all lower caps into CAPS
x.upper()

# The find function will find the char in the string where as index will find the index of the char.
# if the index of a char is not present then idex will through an error
x.find('o')
x.find('w')
# Index will locate and will display the index of the char
x.index('o')
# As you can see index as through an error because was not present in the memory
x.index('w')
# will spilt each word
x = 'Hello World!! Python is great and I will learn it'
x.split(' ')

y = x.split(' ')
a = ' '
print(a.join(y))<jupyter_output>Hello World!! Python is great and I will learn it<jupyter_text>3. Boolean:  AND Operator<jupyter_code>False and False


False and True


True and False
True and True
(3 > 2) and (5 < 4)
(3 > 2) and (5 > 4)<jupyter_output><empty_output><jupyter_text>OR Operator<jupyter_code>False or False
True or False
False or True
False or True
True or True<jupyter_output><empty_output><jupyter_text>NOT Operator<jupyter_code>not True
not False
not (4 > 2)
not (4 > 2)<jupyter_output><empty_output><jupyter_text>3.2. Implicit Boolean:<jupyter_code>x = []
y = [1,2,3]

if x:
    print('Not empty.')
else:
    print('Empty!')
if y:
    print('Not empty.')
else:
    print('Empty!')<jupyter_output>Not empty.<jupyter_text>List<jupyter_code># Display all elements
a = [5,6,4,8,9]
a[:] 
a= [1,2,3,['a','b','c'],4,5]
print(a[3:5])    
# while printing it will not consider the last index
print(a[3][:2])
# Concatenation
a = [5,6,4,8,9]
b= [8,7,6,9,10]
c = a+b
print(c)
# while replaing after the range is over then it will place the value at the end of the string
a =[1,7,3]
a[1:3]
a[1:3] =[3,5,7]
print(a)<jupyter_output>[1, 3, 5, 7]<jupyter_text>Session 02  List Inside a  list<jupyter_code># List inside a list
# In this we will find the index and then go to that index and then replace the value with an list 
a =[1,7,3]
a[2] =[3,5,7]
print(a)<jupyter_output>[1, 7, [3, 5, 7]]<jupyter_text>Delete a value from list using in index 1) Delete one value from the list<jupyter_code># this will delete an value at the given index
a= [1,6,6,8,0]
del a[4]
print(a)<jupyter_output>[1, 6, 6, 8]<jupyter_text>2) Delete alot items from list using the range.<jupyter_code># In this we can also remove a part of the list
b= [7,8,0,7,12,16]
del b[1:4]
print(b)<jupyter_output><empty_output><jupyter_text>Function is the list  Sort Function 1) Sort Problem<jupyter_code># sort function will not work with different data type
# Data TYpe must be same
a= [5,7,1,'a','b']
a.sort()
print(a)<jupyter_output><empty_output><jupyter_text>2) Sort the List in deceding order<jupyter_code>a =[5,6,8,1,0]
a.sort(reverse=True)
print(a)<jupyter_output>[8, 6, 5, 1, 0]<jupyter_text>3) Sort the list using accesding order<jupyter_code>a =[5,6,8,1,0]
a.sort()
print(a)<jupyter_output>[0, 1, 5, 6, 8]<jupyter_text>Append Function 1) Adding one value using append<jupyter_code>a =[5,6,8,1,0]
a.append(10)
print(a)<jupyter_output>[5, 6, 8, 1, 0, 10]<jupyter_text>2) Problem with Append & Add list inside an list using append<jupyter_code># Append can only add one value at a time,
# if more then one values are added then append will add then as a list so list inside a list.
a =[5,6,8,1,0]
a.append(4)
a.append([10,5])
print(a)<jupyter_output>[5, 6, 8, 1, 0, 4, [10, 5]]<jupyter_text>Reverse Function<jupyter_code>a =[5,6,8,1,0]
a.reverse()
print(a)<jupyter_output>[0, 1, 8, 6, 5]<jupyter_text>Sorted Function  Difference Between Sort() and Sorted() **1) Sorted() function** The only difference is that sorted will only show that the values are sorted but in realitty the values will not be sorted. The main list will not change.**2) Sort() function**The sort function will sort all of the values in a list.The main list will be changed<jupyter_code>a =[5,6,8,1,0]
sorted(a)
print(sorted(a))
print(a)<jupyter_output>[0, 1, 5, 6, 8]
[5, 6, 8, 1, 0]<jupyter_text>New Topic  Tuple 1) Tuple Inside a list<jupyter_code>List =[1,4,5,7]
Tuple = (3,5,2)
List.append(Tuple)
print(List)<jupyter_output>[1, 4, 5, 7, (3, 5, 2)]<jupyter_text>2) List inside a Tuple<jupyter_code># You can not add a list inside a tuple using append 
# because the values in the tuple does not change
List =[1,4,5,7]
Tuple = (3,5,2)
Tuple.append(List)
print(Tuple)<jupyter_output><empty_output><jupyter_text>3) You can place a list inside a tuple whenyou are declaring the tuple but once done then the values can not be changes<jupyter_code>Tuple = (3,5,2,[4,5,7])
print(Tuple)<jupyter_output>(3, 5, 2, [4, 5, 7])<jupyter_text>4) Tuple inside a tuple is possiableOnly you can find a tuple inside a tuple at the point of decleartion<jupyter_code>Tuple = (3,5,2,(4,5,7))
print(Tuple)<jupyter_output>(3, 5, 2, (4, 5, 7))<jupyter_text>5) Deleteing the values is not possiable You can only delete the whole object not the element.<jupyter_code>Tuple = (3,5,2,(4,5,7))
del Tuple<jupyter_output><empty_output><jupyter_text>New Topic  Dictionary 1) Dictionary is the collection of key and the values in pir2) Data is accessed using the Keys in the dictionary like primary key in the database3) You can use normal function to get the data from the dictionary.4) Key used {} brackets,5) Dictionary is not used that much but when needded it can help throug  Geneating the basic Code:<jupyter_code>a = {}
b = {'Name':'James','Gender':'Male','Age':45}
c = {1:'Life', 2: 'is', 3: 'Short'}
print (b)
print(c)<jupyter_output>{'Name': 'James', 'Gender': 'Male', 'Age': 45}
{1: 'Life', 2: 'is', 3: 'Short'}<jupyter_text>List inside a dictinary1) You can create a list inside a dictionary<jupyter_code>a = {}
b = {'Name':'James','Gender':'Male','Age':45}
c = {1:'Life', 2: 'is', 3: 'Short'}
d = {1:'Life', 2: 'is', 3: [1,4,5] }
print(d)
print (b)
print(c)<jupyter_output>{1: 'Life', 2: 'is', 3: [1, 4, 5]}
{'Name': 'James', 'Gender': 'Male', 'Age': 45}
{1: 'Life', 2: 'is', 3: 'Short'}<jupyter_text>Tuple inside a  DisctionaryIs it possiable?? Yes, it is.<jupyter_code>a = {}
b = {'Name':'James','Gender':'Male','Age':45}
c = {1:'Life', 2: 'is', 3: 'Short'}
d = {1:'Life', 2: 'is', 3: (1,4,5) }
print(d)
print (b)
print(c)<jupyter_output>{1: 'Life', 2: 'is', 3: (1, 4, 5)}
{'Name': 'James', 'Gender': 'Male', 'Age': 45}
{1: 'Life', 2: 'is', 3: 'Short'}<jupyter_text>Dictionary inside a dictionary<jupyter_code>a = {}
b = {'Name':'James','Gender':'Male','Age':45}
c = {1:'Life', 2: 'is', 3: 'Short'}
d = {'x':[1,2,3], 'y': [4,5,6]}
e = {1:'d',3:'e'}
print(a)
print (b)
print(c)
print(d)
print (e)<jupyter_output>{}
{'Name': 'James', 'Gender': 'Male', 'Age': 45}
{1: 'Life', 2: 'is', 3: 'Short'}
{'x': [1, 2, 3], 'y': [4, 5, 6]}
{1: 'd', 3: 'e'}<jupyter_text>Calling some parts using the Key in Distionary<jupyter_code>b['Name']
e[1]<jupyter_output><empty_output><jupyter_text>Adding Values in the Dictionary<jupyter_code>b= {}
b['Name']="Rafay"
b['Age']=67
b['Gender']="Male"
print(b)<jupyter_output>{'Name': 'Rafay', 'Age': 67, 'Gender': 'Male'}<jupyter_text>Check the number of keys<jupyter_code>b.keys()<jupyter_output><empty_output><jupyter_text>Check the values in the key:You can use print function or the items functions<jupyter_code>b.items()<jupyter_output><empty_output><jupyter_text>Get a Specific Value from the Dictionary1) Fetch the value using the key only<jupyter_code>b.get('Name')<jupyter_output><empty_output><jupyter_text>In Functions in Dictionaryin will tell you that Key exist or not in the dictionary.  Sets  Basic Concept:1) Elements are not repearted 2) There is no concept of ordring(sorting) or indexing 3) Set is the collection of Data<jupyter_code>set1= set([1,4,5,6])
set1<jupyter_output><empty_output><jupyter_text>Coding Exercise 03  1: List  1.1: Creating List<jupyter_code>x= [1,3,True, False, 'Hello', [5,6,7,]]
type(x)
# this calculate the range from the given list
range(1,5)
# This will list the range
x = list(range(1,5))
x
list(range(1,10,2))
list(range(0,21,5))<jupyter_output><empty_output><jupyter_text>1.2: Indexing and Slicing list<jupyter_code>x = [1,2,['life','is']]
x[1]
# Accessing value using the index from the list 
x[2]
# Accessing the data from the list inside a list
x[2][1]
# the process is that the counter will go to the provided index and at 
# that idex will print the value from the list
x =[1,2,3,['a','b','c'],4,5]
x[3][:2]<jupyter_output><empty_output><jupyter_text>1.3: Opeeration with the lists:<jupyter_code>a=[1,2,3]
b= [4,5,6]
a+ b

x = [1, 2, 3]
x*3<jupyter_output><empty_output><jupyter_text>1.4: Changing the content:<jupyter_code># the counter will go the index and will change the value according to 
#the user
x= [1,2,3]
x[1] = -1
x
x[1:2] =[3,5,7,9,11]
x
# Changing somepart of the list
x = [1, 2, 3]
x[1:2] = [-1, -2, -3]
x
# Changing some elements of the list
x = [1, 2, 3]
x[1] = [-1, -2, -3]
x<jupyter_output><empty_output><jupyter_text>1.5: Deleting List<jupyter_code># Deleteing part of the list
x= [1,3,2,4,5,6,7,8,9]
x[1:3] =[]
x
# Delete some values at  index from the list
x= [1,3,2,4,5,6,7,8,9]
del x[2]
x<jupyter_output><empty_output><jupyter_text>1.6: Functions in the List:<jupyter_code># checking the length of the lsit
x= [1,3,2,4,5,6,7,8,9]
len(x)

#adding values in the list using append function
x= [1,3,2,4,5,6,7,8,9]
x.append(4)
x.append([5,6])
x
# Now we will reverse the list
x= [1,3,2,4,5,6,7,8,9]
x.reverse()
x
# now we will sort the list
x= [1,3,2,4,5,6,7,8,9]
x.sort()
x
# now we will sorted reverse the list
x= [1,3,2,4,5,6,7,8,9]
x.sort(reverse=True)
x
# now we will sort the list
x= [1,3,2,4,5,6,7,8,9]
sorted(x)
x<jupyter_output><empty_output><jupyter_text>2: Tuple:   2.1: Creating Tuple<jupyter_code>x = (1, 3, True, False, 'Hello', [3,5,7])
type(x)
# checking the range in the tuple
x= tuple(range(1,5))
x<jupyter_output><empty_output><jupyter_text>2.2:  Indexing And Slicing Tuple:<jupyter_code>x = (1, 2, ('Life', 'is'))
x[2]
x[2][1]
x = (1, 2, 3, ['a', 'b', 'c'], 4, 5)
x[3][:2]<jupyter_output><empty_output><jupyter_text>2.3: Operation with Tuples:<jupyter_code>a = (1, 2, 3)
b = (4, 5, 6)
a + b
a*3<jupyter_output><empty_output><jupyter_text>3: Dictionary   3.1: Creating Dicctionaries:<jupyter_code>d = {'x':[1,2,3], 'y':[4,5,6]}
d['x']
x['y']<jupyter_output><empty_output><jupyter_text>3.2: Adding key Values<jupyter_code>d = {}
d['name'] = 'John'
d['gender'] = 'Male'
d['age'] = 23
d
del d['age']
d
d['name'] = 'Andrew' 
d<jupyter_output><empty_output><jupyter_text>3.3. Dictionary methods and operations:<jupyter_code>d.keys()
d.values()
d.items()
d.clear()
d
d = {'name': 'John', 'gender': 'Male', 'age': 23} 
d.get('wage', 0)`
# Check whether 'name' is a key of d.
'name' in d
# Check whether 'wage' is a key of d.
'wage' in d<jupyter_output><empty_output><jupyter_text>4: Sets:  4.1: Creating Sets:<jupyter_code>b = set([1,2,3,3,3,3,4,5])
b<jupyter_output><empty_output><jupyter_text>4.2: operations with Sets:<jupyter_code>s1 = set([1, 2, 3, 4, 5])
s2 = set([4, 5, 6, 7, 8])
s1 & s2
s1.intersection(s2)


s1 | s2


s1.union(s2)

s1 - s2
s1.difference(s2)


a = set([1, 2, 3, 4, 5]) 
a.add(6)
a


a.update([7, 8, 9])
a
a.remove(9)
a
print("End of Exercise")<jupyter_output>End of Exercise
{'fraction_non_alphanumeric': 0.16402239850676623, 'fraction_numerical': 0.05070773059573806, 'mean_word_length': 5.913440860215053, 'pattern_counts': {'":': 0, '<': 182, '<?xml version=': 0, '>': 186, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '51', 'dir': 'jupyter-structured-clean-dedup', 'id': '482682', 'license': 'MIT', 'n_tokens_mistral': 5654, 'n_tokens_neox': 5340, 'n_words': 1566, 'path': 'Rafay notes/Samsung Course/Chapter 2/Class Work/Lecture 03 Wednesday/Class Work Notes and Exercise  29 Septermber 2021.ipynb', 'repo_name': 'rafay99-epic/Ssmsunng-Innovation-Campus-Notes', 'size': '12858'}