Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Average.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Average - Create a function that takes a list as an argument and returns the average of all the values in the list.
# For example multiples([1,2,3,4]) should return #2.5

def average(num_list):
sum = 0
count = 0
for n in num_list:
sum = sum + n
count +=1
average = sum/count
return average

print(average([1,2,3,5]))
14 changes: 14 additions & 0 deletions Biggie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#Biggie Size - Given a list, write a function that changes all positive numbers in the list to "big".
# Example: make_it_big([-1, 3, 5, -5]) returns that same list, #changed to [-1, "big", "big", -5].


def make_it_big(num_list):
big_list = []
for n in num_list:
if n > 0:
big_list.append("big")
else:
big_list.append(n)
return big_list

print(make_it_big([-1,3,5,-5]))
17 changes: 17 additions & 0 deletions Count_Positives.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#Count Positives - Given a list of numbers, create a function to replace last value with number of positive values.
# Example, count_positives([-1,1,1,1]) changes list #to [-1,1,1,3] and returns it.
# (Note that zero is not considered to be a positive number).

def count_positives(num_list):
count = 0
new_list = []
for n in num_list:
if n > 0:
count +=1
new_list.append(n)
else:
new_list.append(n)
new_list[len(num_list)-1] = count
return new_list

print(count_positives([-1,1,1,1]))
16 changes: 16 additions & 0 deletions Fibonacci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#Fibonacci- The Fibonacci numbers, commonly denoted F(n) form a sequence,
#called the Fibonacci sequence, such that each number is the sum of the two preceding ones, #starting from 0 and 1. That is,
#F(0) = 0, F(1) = 1
#F(n) = F(n - 1) + F(n - 2), for n > 1.
#Create a function that accepts any number and will create a sequence based on the fibonacci sequence.

def Fibonacci(n):

if n == 0:
return 0
elif n == 1 or n == 2:
return 1
else:
return Fibonacci(n -1) + Fibonacci(n - 2)

print(Fibonacci(9))
19 changes: 19 additions & 0 deletions FizzBuzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#Fizzbuzz- Create a function that will print numbers from 1 to 100, with certain exceptions:
#If the number is a multiple of 3, print “Fizz” instead of the number.
#If the number is a multiple of 5, print “Buzz” instead of the number.
#If the number is a multiple of 3 and 5, print “FizzBuzz” instead of the number.

def fizz_buzz(start,end):
numbers = []
for n in range(start,end+1):
if n % 3 == 0 and n % 5 == 0:
numbers.append("FizzBuzz")
elif n % 3 == 0:
numbers.append("Fizz")
elif n % 5 == 0:
numbers.append("Buzz")
else:
numbers.append(n)
return numbers

print(fizz_buzz(1, 100))
15 changes: 15 additions & 0 deletions IsPalindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#Ispalindrome- Given a string, write a python function to check if it is palindrome or not.
# A string is said to be palindrome if the reverse of the string is the same as string.
# For example, “radar” is a palindrome, but “radix” is not a palindrome.
def is_palindrome(input_string):
new_string = input_string.lower().replace(' ', '')
reverse_string = new_string[::-1]
print(new_string)
print(reverse_string)
if new_string == reverse_string:
return True
return False



print(is_palindrome("Never Odd Or Even"))
7 changes: 7 additions & 0 deletions Length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#Length - Create a function that takes a list as an argument and returns the length of the list.
#For example length([1,2,3,4]) should return 4

def length(num_list):
return(len(num_list))

print(length([1,2,3,4]))
12 changes: 12 additions & 0 deletions Maximum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#Maximum - Create a function that takes a list as an argument and returns the maximum value in the list.
# If the passed list is empty, have the function return false.
# For example maximum([1,2,3,4]) should return 4; maximum([-1,-2,-3]) should return -1.

def maximum(num_list):
if(len(num_list) == 0):
return False
else:
max_value = max(num_list)
return max_value

print(maximum([-1,2,3]))
14 changes: 14 additions & 0 deletions Minimum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#Minimum - Create a function that takes a list as an argument and returns the minimum value in the list.
# If the passed list is empty, have the function return false.
# For example minimum([1,2,3,4]) should return 1; minimum([-1,-2,-3]) should return -3.

def minimum(num_list):
if(len(num_list) == 0):
return False
else:
min_value = min(num_list)
return min_value


print(minimum([-1,-2,-3]))

9 changes: 9 additions & 0 deletions ReverseList.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ReverseList - Create a function that takes a list as a argument and return a list in a reversed order.
# Do this without creating a empty temporary list.
# For example #reverse([1,2,3,4]) should return [4,3,2,1]. This challenge is known to appear during basic technical interviews.

def reverse(num_list):
reverse_list = sorted(num_list, reverse=True)
return reverse_list

print(reverse([1,2,3,4]))
10 changes: 10 additions & 0 deletions SumTotal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#SumTotal - Create a function that takes a list as an argument and returns the sum of all the values in the list.
# For example sum_total([1,2,3,4]) should return 10

def sum_total(num_list):
sum = 0
for n in num_list:
sum = sum + n
return sum

print(sum_total([1,2,5,4]))
54 changes: 54 additions & 0 deletions UltimateAnalyze.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#Ultimate_analyze - Create a function that takes a list as an argument and returns a dictionary
# that has the sumTotal, average, minimum, maximum and length of the list.






def sumTotal(num_list):
sum = 0
for n in num_list:
sum = sum + n
return sum

def average(num_list):
sum = 0
count = 0
for n in num_list:
sum = sum + n
count +=1
average = sum/count
return average

def minimum(num_list):
if(len(num_list) == 0):
return False
else:
min_value = min(num_list)
return min_value

def maximum(num_list):
if(len(num_list) == 0):
return False
else:
max_value = max(num_list)
return max_value

def length(num_list):
return(len(num_list))



def ultimate_analyze(num_list):
dict = {}

dict['sumTotal'] = sumTotal(num_list)
dict['average'] = average(num_list)
dict['minimum'] = minimum(num_list)
dict['maximum'] = maximum(num_list)
dict['length'] = length(num_list)
return dict


print(ultimate_analyze([1,2,3,4,5,6]))
Binary file added __pycache__/Average.cpython-311.pyc
Binary file not shown.
Empty file added data_engineer/user_table.ipynb
Empty file.
63 changes: 63 additions & 0 deletions data_engineer/xml_practice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import xml.etree.ElementTree as ET
tree = ET.parse('movies.xml')
root = tree.getroot()
print('Starting...')
print(f'root.tag {root.tag}')
print(root.attrib)
for child in root:
print(child.tag, child.attrib)


print([elem.tag for elem in root.iter()])
print(ET.tostring(root, encoding = 'utf8').decode('utf8'))
for movie in root.iter('movie'):
print(movie.attrib)
for description in root.iter('description'):
print(description.text)
for movie in root.findall("./genre/decade/movie/[year='1992']"):
print(movie.attrib)

for movie in root.findall("./genre/decade/movie/format/[@multiple='Yes']..."):
print(movie.attrib)

for movie in root.iter('movie'):
print(movie.attrib)
#bt2f = root.find("./genre/decade/movie[@title = 'Back 2 the Future']")
#bt2f.attrib['title'] = 'Back to the Future'
#tree.write('movies.xml')
#tree = ET.parse('movies.xml')
root = tree.getroot()
for movie in root.iter('movie'):
print(movie.attrib)
for form in root.findall("./genre/decade/movie/format"):
print(form.attrib, form.text)

for decade in root.findall("./genre/decade"):
print(decade.attrib)
for year in decade.findall("./movie/year"):
print(year.text, '\n')

action = root.find("./genre[@category='Action']")
new_dec = ET.SubElement(action, 'decade')
new_dec.attrib["years"] = '2000s'
print(ET.tostring(action, encoding='utf8').decode('utf8'))
xmen = root.find("./genre/decade/movie[@title='X-Men']")
dec2000s = root.find("./genre[@category='Action']/decade[@years='2000s']")
dec2000s.append(xmen)
dec1990s = root.find("./genre[@category='Action']/decade[@years='1990s']")
dec1990s.remove(xmen)
print(ET.tostring(action, encoding='utf8').decode('utf8'))

animation = root.find("./genre")
anime_genre = ET.SubElement(root, 'genre')
anime_genre.attrib['category'] = 'Animation'
animation1 = root.find("./genre[@category='Animation']")
new_anime = ET.SubElement(animation1, 'decade')
new_anime.attrib["years"] = '1990s'
print(ET.tostring(anime_genre, encoding='utf8').decode('utf8'))
bat_man = root.find("./genre/decade/movie[@title = 'Batman Returns']")
new_genre = root.find("./genre[@category='Animation']/decade[@years='1990s']")
new_genre.append(bat_man)
old_genre = root.find("./genre[@category='Action']/decade[@years='1990s']")
old_genre.remove(bat_man)
print(ET.tostring(root, encoding='utf8').decode('utf8'))
9 changes: 9 additions & 0 deletions lambda_functions/filter_list1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Filter the list so that it only contains languages with 'a' in it.

prog_lang = [('Python', 3.8),
('Java', 13),
('JavaScript', 2019),
('Scala', 2.13)]

filter_list =list(filter(lambda x: 'a' in x[0], prog_lang))
print(filter_list)
11 changes: 11 additions & 0 deletions lambda_functions/filter_list2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Filter the list so that it only contains languages whose version is in integer
# form.

prog_lang = [('Python', 3.8),
('Java', 13),
('JavaScript', 2019),
('Scala', 2.13)]

filter_list = list(filter(lambda x: isinstance(x[1], int) ,prog_lang))

print(filter_list)
12 changes: 12 additions & 0 deletions lambda_functions/generate_tuple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#Transform the list so that it contains the tuples in the form,
#("language in all lower case", length of the language string)

from functools import reduce

prog_lang = [('Python', 3.8),
('Java', 13),
('JavaScript', 2019),
('Scala', 2.13)]

generate_tuple = reduce(lambda x, y:(x[0]+','+y[0], str(x[1]) +',' + str(y[1])),prog_lang)
print(generate_tuple)
13 changes: 13 additions & 0 deletions lambda_functions/sort_list_asc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Sort the list by each language's version in ascending order.

prog_lang = [('Python', 3.8),
('Java', 13),
('JavaScript', 2019),
('Scala', 2.13)]

prog_lang.sort(key = lambda x:x[1])
print(prog_lang)




10 changes: 10 additions & 0 deletions lambda_functions/sort_list_desc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#Sort the list by the length of the name of each language in descending
#order.

prog_lang = [('Python', 3.8),
('Java', 13),
('JavaScript', 2019),
('Scala', 2.13)]

prog_lang.sort(key = lambda x: x[1],reverse=True)
print(prog_lang)
11 changes: 11 additions & 0 deletions lambda_functions/tuple_list1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#Transform the list so that it contains the tuples in the form,
#("language in all lower case", length of the language string)


prog_lang = [('Python', 3.8),
('Java', 13),
('JavaScript', 2019),
('Scala', 2.13)]

tuple_list = list(map(lambda x : (x[0].lower(),len(x[0])),prog_lang))
print(tuple_list)