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
106 changes: 104 additions & 2 deletions 12_09_practice.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,131 @@
#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 biggie(list):
for i in range(len(list)):
if list[i]>0:
list[i]='big'
return list

print(biggie([-1,3,5,-5]))
#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 positives(list):
count = 0
for i in list:
if i > 0:
count += 1
list[len(list) - 1] = count
return list

print(positives([-1,1,1,1]))


#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 sumtotal(list):
sum = 0
for i in list:
sum += i
return sum

print(sumtotal([1,2,3,4]))
#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(list):
sum = 0
for i in list:
sum += i
return sum/len(list)

print(average([1,2,3,4]))

#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(list):
return len(list)

print(length([1,2,3,4]))

#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(list):
return min(list)

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

#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(list):
return max(list)

print(maximum([1,2,3,4]))

#Ultimateaalyze - Create a function that takes a list as an argument and returns a dictionary that has the sumTotal, average, minimum, maximum ad length of the list.

def ultimateanalyze(list):
dict = {'sumtotal':0, 'average':0, 'minimum': list[0], 'maximum': list[0], 'length': len(list)}
for i in list:
dict['sumtotal'] += i
dict['average'] = dict['sumtotal']/len(list)
if dict['minimum'] > i:
dict['minimum'] = i
if dict['maximum'] < i:
dict['maximum'] = i
return(dict)

print(ultimateanalyze([-2,4,-5,6,10,1,0]))

#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_list(list):
for i in range(len(list) // 2):
list[i], list[-1-i] = list[-1-i], list[i]
return list
print(reverse_list([11,12,13]))
print(reverse_list([11,12,13,14,15,16]))

#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 isPalindrome(str):

for i in range(0, (len(str)/2) ):
if str[i] != str[len(str)-i-1]:
return False
return True

print(isPalindrome('radar'))
print(isPalindrome('radix'))

#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 fizzbuzz():
for i in range(1,101):
if i % 3 == 0 and i % 5 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 ==0:
print("buzz")
else:
print(i)

fizzbuzz()

#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.
#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:
return 1
else:
return ((n-1) + (n-2))

print(fibonacci(5))



6 changes: 6 additions & 0 deletions data_file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"user": {
"name": "William Williams",
"age": 93
}
}
91 changes: 91 additions & 0 deletions json_practice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import json
import requests
from pprint import pp

#serialize a json, encoding data into json format
#deserialize a json, decoding into another format

### !!!! They are NOT perfect inverses !!!!! #####
#
#
#Serialize
#dump() write data to a file like object in json format
#open() in a try and except block
#with open() as

#dumps() write the data to string in json format

data= {
"user": {
"name": "William Williams",
"age": 93
}
}

# print(data["user"]["age"])

with open("data_file.json", "w") as write_file:
json.dump(data, write_file, indent= 4)


json_str=json.dumps(data, indent=4)
print(json_str)

#lets check and se

blkjk_hand= (8, "Q")
encoded = json.dumps(blkjk_hand)
decoded= json.loads(encoded)

print(type(blkjk_hand))
print(type(decoded))
print(blkjk_hand ==tuple(decoded))

##deserializatation example
response = requests.get("http://jsonplaceholder.typicode.com/todos")
todos= json.loads(response.text)

#print(type(todos))
pp(todos[:10])


#see who has the most completed items
#we are going to need to loop through list to check all the todos
#we need to count all the items
#have a place to track and store the number of completed todos, by thu user
todos_by_user={}
for item in todos:
if item["completed"] == True and item["userId"] not in todos_by_user:
if item["userID"] not in todos_by_user.keys():
todos_by_user[item["userId"]] = 1
else:
todos_by_user[item["userId"]] += 1

print(todos_by_user)

#with the code above, we have created a new dictionary that has all of the users with completed
#and the total number of tasks they created

top_users = sorted(todos_by_user.items(), key=lambda x: x[1], reverse=True)
print(top_users)
max_complete= top_users[0][1]

#with the code above we are sorting by the values due to the lambda function sorting at x[1] from high to low

### Final Goal is to tell s in a string who are the users that have the highest number of todos completed with thei user ids 4
stars = [x for x, y in top_users if y == max_complete]

stars2 = []
for users, value in top_users:
if value == max_complete:
stars2.append(users)
print(stars)
print(stars2)


#"Users {} completed {this many} TODOS"

print("User(s) {} completed TODOs".format(user))



120 changes: 120 additions & 0 deletions movies.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<collection>
<genre category="Action">
<decade years="1980s">
<movie favorite="True" title="Indiana Jones: The raiders of the lost Ark">
<format multiple="No">DVD</format>
<year>1981</year>
<rating>PG</rating>
<description>
'Archaeologist and adventurer Indiana Jones
is hired by the U.S. government to find the Ark of the
Covenant before the Nazis.'
</description>
</movie>
<movie favorite="True" title="THE KARATE KID">
<format multiple="Yes">DVD,Online</format>
<year>1984</year>
<rating>PG</rating>
<description>None provided.</description>
</movie>
<movie favorite="False" title="Back 2 the Future">
<format multiple="False">Blu-ray</format>
<year>1985</year>
<rating>PG</rating>
<description>Marty McFly</description>
</movie>
</decade>
<decade years="1990s">
<movie favorite="False" title="X-Men">
<format multiple="Yes">dvd, digital</format>
<year>2000</year>
<rating>PG-13</rating>
<description>Two mutants come to a private academy for their kind whose resident superhero team must
oppose a terrorist organization with similar powers.</description>
</movie>
<movie favorite="True" title="Batman Returns">
<format multiple="No">VHS</format>
<year>1992</year>
<rating>PG13</rating>
<description>NA.</description>
</movie>
<movie favorite="False" title="Reservoir Dogs">
<format multiple="No">Online</format>
<year>1992</year>
<rating>R</rating>
<description>WhAtEvER I Want!!!?!</description>
</movie>
</decade>
</genre>

<genre category="Thriller">
<decade years="1970s">
<movie favorite="False" title="ALIEN">
<format multiple="Yes">DVD</format>
<year>1979</year>
<rating>R</rating>
<description>"""""""""</description>
</movie>
</decade>
<decade years="1980s">
<movie favorite="True" title="Ferris Bueller's Day Off">
<format multiple="No">DVD</format>
<year>1986</year>
<rating>PG13</rating>
<description>Funny movie about a funny guy</description>
</movie>
<movie favorite="FALSE" title="American Psycho">
<format multiple="No">blue-ray</format>
<year>2000</year>
<rating>Unrated</rating>
<description>psychopathic Bateman</description>
</movie>
</decade>
</genre>

<genre category="Comedy">
<decade years="1960s">
<movie favorite="False" title="Batman: The Movie">
<format multiple="Yes">DVD,VHS</format>
<year>1966</year>
<rating>PG</rating>
<description>What a joke!</description>
</movie>
</decade>
<decade years="2010s">
<movie favorite="True" title="Easy A">
<format multiple="No">DVD</format>
<year>2010</year>
<rating>PG--13</rating>
<description>Emma Stone = Hester Prynne</description>
</movie>
<movie favorite="True" title="Dinner for SCHMUCKS">
<format multiple="Yes">DVD,digital,Netflix</format>
<year>2011</year>
<rating>Unrated</rating>
<description>Tim (Rudd) is a rising executive
who 'succeeds' in finding the perfect guest,
IRS employee Barry (Carell), for his boss monthly event,
a so-called 'dinner for idiots,' which offers certain
advantages to the exec who shows up with the biggest buffoon.
</description>
</movie>
</decade>
<decade years="1980s">
<movie favorite="False" title="Ghostbusters">
<format multiple="No">Online,VHS</format>
<year>1984</year>
<rating>PG</rating>
<description>Who ya gonna call?</description>
</movie>
</decade>
<decade years="1990s">
<movie favorite="True" title="Robin Hood: Prince of Thieves">
<format multiple="No">Blu_Ray</format>
<year>1991</year>
<rating>Unknown</rating>
<description>Robin Hood slaying</description>
</movie>
</decade>
</genre>
<genre category="Anime"><decade years="2000s" /></genre></collection>
Loading