Hello! Some simpler python questions. Please provide full comments. Thank you!

1 answer below »
Hello! Some simpler python questions. Please provide full comments. Thank you!
Answered 2 days AfterJan 28, 2021

Answer To: Hello! Some simpler python questions. Please provide full comments. Thank you!

Swapnil answered on Jan 31 2021
139 Votes
75050/1.py
def indexesToCount( aList ):
max = aList[ 0 ]
for a in aList:
if a > max:
max = a
return max
pr
int(indexesToCount([0, 0, 1, 3]))
75050/2.py
def firstCharacters(aString):
result = ""
v = True
for i in range(len(aString)):
if (aString[i] == ' '):
v = True
elif (aString[i] != ' ' and v == True):
result += (aString[i])
v = False
return result
if __name__ == "__main__":
aString = "Hello World"
print(firstCharacters(aString))
75050/3.1.py
import heapq as hq
def addToMinQueue(q, value):
q.sort(reverse = True)
for i in range(value):
print (q[i], end =" ")
q = [1, 2, 3, 4]
value = 1
addToMinQueue(q, value)
def getSmallestValue(q):
result = q[0]
hq.heapify(result)
for row in q[1:]:
for ele in row:
hq.heappush(result,ele)
getSmallestValue = hq.nsmallest(k,result)
print ("Smallest Element is ",getSmallestValue[-1])
if __name__ == "__main__":
q = [[10, 25, 27]]
k = 1
getSmallestValue(q)
75050/3.2.py
import heapq as hq
def addToMaxHeap(q):
hq._heapify_max(q)
q = hq._heappop_max(q)
if __name__ == "__main__":
q = [[10, 25, 27]]
k = 1
addToMaxHeap(q)
def getLargestValue(q):
result = q[0]
hq.heapify(result)
for row in q[1:]:
for ele in row:
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here