<jupyter_start><jupyter_text>Python Basics Class 2  LoopsThe first statement in a code block is executed first, followed by the second, and so on. There may be a situation when you need to execute a block of code several number of times. A loop executes a block of statement until the condition is true. As soon as the condition becomes false the loop stops. Type of loops in python:1. while2. for  While Loop Syntax```while condition:    execute statement```<jupyter_code>count = 0
while count < 3:
    count = count + 1
    # execute these statement until count is 3
    print("Hello Class!")<jupyter_output>Hello Class!
Hello Class!
Hello Class!<jupyter_text>For Loop Syntax```for i in range(start index, end index, step):    execute statements```<jupyter_code># range creates an iterable(think of it as a list of numbers)
for i in range(1,9):
    print(i)
for i in range(1,9,2):
    print(i)
# i goes from 0 to 10
for i in range(0, 11):
    if i >= 5:
        break
    
    if i % 2 == 0:
        print(i)
    else:
        continue
# count number of even numbers between 0 and 10(inclusive)
even = 0

for i in range(0, 11):
    if i % 2 == 0:
        even += 1
        print(i)
    else:
        # skip to next iteration
        continue
        
print(f"Even numbers between 0 and 10(inclusive) are {even}")<jupyter_output>0
2
4
6
8
10
Even numbers between 0 and 10(inclusive) are 6<jupyter_text>ListCollection of different data-types. The first index is zero, the second index is one, and so forth. Index value is the identity of every element.1. Creation2. Modification3. Indexing/Slicing4. Deleting  Slicing Syntax```list[start:end]``` returns a list starting from start index upto the index (end-1)<jupyter_code>my_list = [1, 4.2, "string", 3, 4, 5]
my_list[2]
# from the start uptil the 3rd last element
my_list[:-2]
# from the 3rd element from the end to the last element
my_list[-3:]
# 2nd index from the end
my_list[-2]
# from the 1st index to the 3rd index
my_list[1:4]
print(my_list)
my_list[1] = 5.2
print(my_list)
del my_list[0]
print(my_list)<jupyter_output>[5.2, 'string', 3, 4, 5]<jupyter_text>Operations1. length2. concatenation3. repetition4. iteration<jupyter_code>my_list
x = len(my_list)
print(x)
# repetition
['string', 1] * 4
list2 = ['string1', 1, 9, 0]
list3 = list2 + my_list
print(list3)<jupyter_output>['string1', 1, 9, 0, 5.2, 'string', 3, 4, 5]<jupyter_text>Try ```list3 = my_list + list2```<jupyter_code>print(my_list)<jupyter_output>[5.2, 'string', 3, 4, 5]<jupyter_text>Printing elements of a list<jupyter_code>for x in my_list:
    print(x)
for i in range(len(my_list)):
    print(my_list[i])<jupyter_output>5.2
string
3
4
5<jupyter_text>Multiply every element in the array by 2 and update the element value<jupyter_code>num_list = [1,2,3,4,5]

for i in range(len(num_list)):
    num_list[i] = num_list[i] * 2
num_list<jupyter_output><empty_output><jupyter_text>List functions1. max2. min3. sorted<jupyter_code>num_list_2 = [4, 3, 5, 1]
sorted(num_list_2, reverse=True)
max(num_list_2)<jupyter_output><empty_output><jupyter_text>TuplesThe differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets.<jupyter_code>my_tuple = (2,2,3,'string')
for x in my_tuple:
    print(x)<jupyter_output>2
2
3
string<jupyter_text>Try lists operation on tuples  Strings<jupyter_code>name = "Amol"
# equivalent to name = ['A','m','o','l'](think of it like this but its not exactly)
name[1:3]
for x in name:
    print(x)
string1 = "Amol"
string2 = "Grover"

name = string1 + " " + string2
print(name)
len(name)
string = "A very long sentence#with#multiple spaces"
list_string = string.split('#')
print(list_string)
string = "A very long sentence with multiple spaces"
list_string = string.split(' ')
print(list_string)<jupyter_output>['A', 'very', 'long', 'sentence', 'with', 'multiple', 'spaces']<jupyter_text>DictionaryA dictionary contains a key value pair where every value is accessed by its corresponding key. Since values are accessed by keys therefore keys must be unique in a dictionary. Keys are the identity.<jupyter_code>my_dict = {'name': 'Amol', 'age' : 19, 'year': 2}
my_dict['name']
my_dict['age']
new_dict = {'a': 1, 'b': 2, 'fruit': 'mango', 'key' : 4.2, '2': 4}
len(new_dict)<jupyter_output><empty_output><jupyter_text>Iterating through dictionary Way 1: Accessing keys and values simultaneously<jupyter_code>new_dict.items()
for key, value in new_dict.items():
    print(key, value)<jupyter_output>a 1
b 2
fruit mango
key 4.2
2 4<jupyter_text>Way 2: Access elements using keys<jupyter_code>new_dict.keys()
for i in new_dict.keys():
    print(new_dict[i])<jupyter_output>1
2
mango
4.2
4
{'fraction_non_alphanumeric': 0.11693548387096774, 'fraction_numerical': 0.03438030560271647, 'mean_word_length': 4.825710754017305, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 44, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '146887', 'license': 'MIT', 'n_tokens_mistral': 1797, 'n_tokens_neox': 1679, 'n_words': 561, 'path': 'Python Basics Class 2.ipynb', 'repo_name': 'frextrite/PythonClass', 'size': '4712'}