Answer To: Questions Day 09 Challenges: Challenge 1: write a program that finds all nonsingle letter substrings...
Neha answered on Apr 19 2021
53243/challenge 10.py
from lru import LRU
l = LRU(5)
print (l.peek_first_item(), l.peek_last_item() ) #return the MRU key and LRU key
# Would print None None
for i in range(5):
l[i] = str(i)
print (l.items() ) # Prints items in MRU order
# Would print [(4, '4'), (3, '3'), (2, '2'), (1, '1'), (0, '0')]
print (l.peek_first_item(), l.peek_last_item()) #return the MRU key and LRU key
# Would print (4, '4') (0, '0')
l[5] = '5' # Inserting one more item should evict the old item
print (l.items())
# Would print [(5, '5'), (4, '4'), (3, '3'), (2, '2'), (1, '1')]
l[3] # Accessing an item would make it MRU
print (l.items())
# Would print [(3, '3'), (5, '5'), (4, '4'), (2, '2'), (1, '1')]
# Now 3 is in front
l.keys() # Can get keys alone in MRU order
# Would print [3, 5, 4, 2, 1]
del l[4] # Delete an item
print (l.items())
# Would print [(3, '3'), (5, '5'), (2, '2'), (1, '1')]
print (l.get_size())
# Would print 5
l.set_size(3)
print (l.items())
# Would print [(3, '3'), (5, '5'), (2, '2')]
print (l.get_size())
# Would print 3
print (l.has_key(5))
# Would print True
print (2 in l)
# Would print True
l.get_stats()
# Would print (1, 0)
l.update(5=='0') # Update an item
print (l.items())
# Would print [(5, '0'), (3, '3'), (2, '2')]
l.clear()
print (l.items())
# Would print []
def evicted(key, value):
print ("removing: %s, %s" % (key, value))
l = LRU(1, callback=evicted)
l[1] = '1'
l[2] = '2'
# callback would print removing: 1, 1
l[2] = '3'
# doesn't call the evicted callback
print (l.items())
# would print [(2, '3')]
del l[2]
# doesn't call the evicted callback
print(l.items())
# would print []
53243/day 10/challenge 1.py
import hashlib
#File 1
hasher1 = hashlib.md5()
filename1 = input("Enter complete path of file with file name")
afile1 = open(filename1, 'rb')
buf1 = afile1.read()
a = hasher1.update(buf1)
md5_a=(str(hasher1.hexdigest()))
#File 2
hasher2 = hashlib.md5()
filename2 = input("Enter complete path of file with file name")
afile2 = open(filename2, 'rb')
buf2 = afile2.read()
b = hasher2.update(buf2)
md5_b=(str(hasher2.hexdigest()))
#Compare md5
if(md5_a==md5_b):
print("Yes! Both the files are same")
else:
print("No! Both files are not same")
53243/day 10/challenge 2.py
from simhash import Simhash
print (Simhash('aa').distance(Simhash('bb')))
print (Simhash('aa').distance(Simhash('aa')))
53243/day 10/challenge 3.py
import requests
jokeitem = input("You want a joke on? ")
information =...