<jupyter_start><jupyter_text>Exercise Data Types 1 - What are the Python most common built-in data types?    Give examples creating variables for each of them.<jupyter_code>an_integer = 2
a_float = 2.5
a_string = 'learning python is fun'
list1 = [1,2,5,'lists are capable of storing multiple types']
boolean = an_integer>a_float<jupyter_output><empty_output><jupyter_text>2 - Exemplify at least 5 ways to convert data types, using the variables that were created in the previous question:<jupyter_code>float(an_integer)
int(a_float)
list(a_string)
str(an_integer)
str(a_float)<jupyter_output><empty_output><jupyter_text>3- Exemplify the use of individual or combined built-in data types to create the following data structures:  + A medical record  + A pixel matrix in RGB format  + A set of geographical coordinates representing the Mayor's Office and The fire brigade in 5 different cities<jupyter_code>medical_record = 'Abdominal pain, weakness and headaches'<jupyter_output><empty_output><jupyter_text>Here I'll show a RGB array.<jupyter_code>from imageio import imread
import numpy as np
rgb_matrix = np.array(imread('https://viajando.expedia.com.br/wp-content/uploads/2015/11/Beirute-Libano.jpg'))
#rgb_list = rgb_matrix.tolist()<jupyter_output><empty_output><jupyter_text>A RGB matrix can be converted to a list of lists<jupyter_code>#rgb_list
image_shape = rgb_matrix.shape
width = image_shape[0]
height = image_shape[1]

print(f"The image  has {height*width} pixels and the resolution is {height} X {width}")
print(rgb_matrix)
coordinates = [(-33.382523,	-70.584099),(40.739582,-73.988358),(48.866081,2.316417)]<jupyter_output><empty_output><jupyter_text>4- Give some examples on how to access the data in the data structures created in the previous question:<jupyter_code>medical_record[10:14]
medical_record.split()[0]<jupyter_output><empty_output><jupyter_text>Acessando o RGB do primeiro pixel<jupyter_code>rgb_list[0][0]
coordinates[0]
coordinates[0][0]<jupyter_output><empty_output><jupyter_text>5- Explain with examples the differences between:  + Mutable and immutable types  + Container types  + Sequential types<jupyter_code>#lists are mutable

list1.append('last_object')
list1
# strings are immutable

a_string.capitalize() 
a_string
# Container types: tuple, list, set, dict<jupyter_output><empty_output><jupyter_text>A sequence is the generic term for an ordered set. The most important sequential types: **string, tuple, lists**Containers are any object that holds an arbitrary number of other objects (Stackoverflow) For example **set** is a container type, but it is not a sequential type<jupyter_code>new_set = set([70, 52, 65, 120, 3, 1])
new_set
new_set[0]
#new_dict = {'two':2,'four':4}
#new_dict[0]<jupyter_output><empty_output><jupyter_text>6- Exemplify method calls on variables associated with data types that:+ Do not modify the variable and do not return values when the method is called  + Modify the variable but do not return values when the method is called  + Do not modify the variable but return values to the method call  + Modify the variable and return values to the method call<jupyter_code># Do not modify the variable and do not return values when the method is called
print(a_string)
# Modify the variable but do not return values when the method is called 
list1.append('variable')
# Do not modify the variable but return values to the method call 
# a method in an immutable object
a_string.capitalize()
list1.count('variable')
# Modify the variable and return values to the method call  
list1.pop()<jupyter_output><empty_output><jupyter_text>7- Exemplify the use of methods for:+ Test whether a string can be converted to an integer  + Test if a set is a subset of another set    + Concatenate two lists  + Count the occurrences of an element in a list<jupyter_code># a)
string_test = '15'
print(string_test.isdigit())
# b)

subset_test = set([1,2,3])
set_test = set(range(10))
subset_test.issubset(set_test)
# c)
list_1 = [2,3, 'random_string']
list_2 = [6.8, [24,25,26]]

# in-place
#list_1.append(list_2)

# creating another list

list_3 = list_1 + list_2
# d)

list_4 = ['VALE3', 'B3SA3', 'PETR4', 'BBAS3', 'VVAR3', 'VALE3', 'B3SA3', 'PETR4', 'BBAS3', 'VVAR3', 'VALE3', 'B3SA3', 'PETR4', 'BBAS3', 
          'VVAR3', 'VALE3', 'B3SA3', 'PETR4', 'BBAS3', 'VVAR3', 'VALE3', 'B3SA3', 'PETR4', 'BBAS3', 'VVAR3', 'VALE3', 'B3SA3', 'PETR4',
          'BBAS3', 'VALE3', 'B3SA3', 'PETR4', 'BBAS3', 'VALE3', 'B3SA3', 'PETR4', 'VALE3', 'B3SA3', 'VALE3']

list_4.count('VALE3')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11069624423457061, 'fraction_numerical': 0.038655831320008785, 'mean_word_length': 6.082426127527216, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 46, 'https://': 1, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '333158', 'license': 'Apache-2.0', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1564, 'n_words': 492, 'path': 'Exercises/1_Data_Types_Exercise_solutions.ipynb', 'repo_name': 'viguardieiro/Python_Course', 'size': '4553'}