<jupyter_start><jupyter_text>**Created by <NAME>****Data Structures****15 of November, 2020**  Content- Lists- Tuples- Dictionaries- Sets  List - List Comprehension- Updateable- Can take different data types- Define with list() function or [] square brackets<jupyter_code>grades = [76,23,5,6,78]
grades
type(grades)
grades[0]
grades[1]
type(grades[2]) #Type of list is list but type of element can be different
confused = list([3,52,"a","name",3.45])
confused
confused[2]
len(confused)
grades= [[36,23,90],[56,44,42],"grades"]   # We can define list in list
grades
len(grades)
grades[0]
grades[0][0] # Element of list in list
type(grades[0][0])
a = [1,2,4,5]
b = [2,3,4,5,[2,4,5,6,]]
all= list([a,b]) #Merging lists
all
del a # Deleting a list
new_list = list([1,2,3,4,5])
new_list
new_list[:2]
new_list[3:]
new_list[::2]
names = ["Josh","Amanda","Kobe","Monish"]
names[0]= "Berkay" #Changing element of list
names
names[1:] = "Jone","Michael","Hoke"
names
names = names + ["Caren"] #Adding element to a list
names
names.append("Dave") #Adding element to a list with append() method
names
del names[2] #Deleting an element by index
names
dir(names)
names.remove("Jone") #Deleting an element by element with remove() method
names
names.insert(1,"Jashua")# Adding an element by index with insert() Method
names
names.insert(len(names),"Barrel")
names
names.pop(0) #Deleting an element by index
names
names.count("Hoke") # Count an element with count() method
names_copy = names.copy() # Makes copy of a list
names.extend(["Harrel","Katy"]) # Merging 2 list
names
names.index("Caren") #Index of an element
names.reverse() #Reverse of a list
names
names.sort() #Sorts elements in the list
names
names.clear() #Clears the list
names<jupyter_output><empty_output><jupyter_text>Tuples- Can't be changed- Able to be indexed- Can take different data types<jupyter_code>t = ("John","Maria",1,23,5.6,[2,45,6]) # Tuples can be created with brackets
t
type(t)
tup = tuple([1,2,4,"Mike"]) # Tuples can be created with tuple() function, but don't forget square brackets inside function
tup
type(tup)
one_tuple = ("Names",) # Add a comma at the end for one-element tuples
one_tuple
type(one_tuple)
t
t[0]
t[2:]
# t[2] = 99 > It gives error, tuples can't be changes<jupyter_output><empty_output><jupyter_text>NamedTuplePython supports a type of container like dictionaries called “namedtuple()” present in module, “collections“. Like dictionaries they contain keys that are hashed to a particular value. But on contrary, it supports both access from key value and iteration, the functionality that dictionaries lack.<jupyter_code>from collections import namedtuple
incomes = (10000,5500,7000,9200)
jobs = namedtuple("Job", ["JR_Data_Scientist","Senior_Software_Engineer","Big_Data_Developer","ML_Engineer"])
incomes= jobs(10000,5500,7000,9200)
incomes.Big_Data_Developer
incomes.ML_Engineer
incomes[0]<jupyter_output><empty_output><jupyter_text>Dictionaries- Mutable- There is no index- Can take multiple data types<jupyter_code>dic = {"Name": "Josh","Age":24, "Job":"ML Developer","Income":9200} # Dictionaries can be created with {} brackets
dic
type(dic)
len(dic)
dic.keys() # Keys can be seen with keys() functions
dic.values() # Values can be seen with values() functions
dic["Name"]
dic["Age"]
dic = {"Name":"Josh",
        "Age":24, 
        "Job":"ML Developer",
        "Income":9200,
        "Location":"Ohio",
        "Languages": ["Python","Scala","Julia"]}
dic
len(dic)
dic["Location"]
# Josh moved to San Francisco - Change the location
dic["Location"] = "San Francisco"
dic
dic["Languages"]
dic["Languages"][0]
d = {"Apartment_1":{"Peoples": ["Josh","Kennedy"], "Income": 15000},
     "Apartment_2":{"Peoples": ["Harry","Mike","James"], "Income": 19000},
     "Apartment_3":{"Peoples": ["Berry","Julia"], "Income": 21000}} # Dictionary can contain a dictionary
d
type(d)
d["Apartment_1"]
d["Apartment_1"]["Peoples"]
d["Apartment_1"]["Peoples"][0]
d["Apartment_4"] = {"Peoples": ["Hans","Flurry"], "Income": 16000} # We can directly add an element with a new key
d
d["Apartment_3"] = {"Peoples": ["Michael","Kevin"], "Income": 26000} # We can change values with same way
d
del d["Apartment_4"] # We can directly delete an element with del
d
d[1] = {"Peoples": ["Hans","Flurry"], "Income": 16000} # Keys can also be a integer
d
d[1]<jupyter_output><empty_output><jupyter_text>Sets- Changeable- Not able to be indexed- Hold unique values<jupyter_code>s = set([1,2,3,4]) # sets can be created with set() function
s
type(s)
s2 = set([1,2,2,2,3,4,5,4,4,5,4,2])
s2 # It gets just unique values
l = ["Jonh",1,"Jonh",1,"Katy",2,2,3]
s3 = set(l)
s3
sentence = "Look at the course!"
s4 = set(sentence)
s4 # It gets just unique values
print("Lenght of Sentence: ", len(sentence))
print("Lenght of S4: ",len(s4))
s5 = set(["I","learn","data","science"])
s5
s5.add("on my own") # Add() helps to add new value
s5
s5.remove("on my own") # remove() helps to remove a value
s5
s5.discard(5) # discard() function helps to prevent producing error
s5
set1 = set([1,2,3,4,5])
set2 = set([2,4,5,6,8])
set1.difference(set2) # difference() function helps to get difference of 2 set
set1-set2 # - helps to get difference of 2 set
set2-set1
set1.symmetric_difference(set2) # symmetric_difference() function helps to get values in not both of them
set1.intersection(set2) # intersection() function helps to get intersection of 2 set
set1&set2 # & helps to get intersection of 2 set
set2.intersection(set1)
set2
set1.union(set2) # union() function helps to get union of 2 set
set2.intersection_update(set1) # intersection_update() function helps to get intersection of 2 set and assign it to first variable
set2
set3 = set([1,2,3,4,5,6,7,8])
set4 = set([4,5,6,7,8])
set3.isdisjoint(set4) # We query if intersection of two set is blank with isdisjoint() function
set3.issubset(set4) # We query if set 3 is a subset of set4 with issubset() function
set3.issuperset(set4) # We query if set 3 contains set4 with issuperset() function<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15029860650298607, 'fraction_numerical': 0.04562043795620438, 'mean_word_length': 6.026806526806527, 'pattern_counts': {'":': 25, '<': 22, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '401779', 'license': 'MIT', 'n_tokens_mistral': 2268, 'n_tokens_neox': 2101, 'n_words': 671, 'path': 'Data Structures.ipynb', 'repo_name': 'arindam-mallik/Data-Science-Tutorials-I', 'size': '6033'}