# Programming Data Structures And Algo Using Python Assignment 3 Answers

Programming, Data Structures And Algo Using Python Assignment 3 Answers 2022:- In This article, we have provided the answers of Programming, Data Structures And Algo Using Python Assignment 3. You must submit your assignment to your own knowledge.

## Programming Data Structures And Algorithms Using Python Assignment 3 Answers [July 2022] Programming Assignment

Q1. Write three Python functions as specified below. Paste the text for all three functions together into the submission window. Your function will be called automatically with various inputs and should return values as specified. Do not write commands to read any input or print any output.

Code:-

``````def contracting(l):
for z in range(0,len(l)-3):
A=abs(l[z+2]-l[z+1])
B=abs(l[z+1]-l[z])
if A<B:
continue
else:
return (False)
return (True)

def counthv(l):
hill_count,valley_count=0,0
if len(l)>2:
for i in range(1,len(l)-1):
if l[i]>l[i-1] and l[i]>l[i+1]:
hill_count+=1
elif l[i]<l[i-1] and l[i]<l[i+1]:
valley_count+=1
return ([hill_count,valley_count])

def leftrotate(m):
ans=list()
for a in range(len(m)):
ans.append([])
for b in range(len(m)):
ans[a].append(m[b][len(m)-a-1])
return(ans)  ``````

## Programming, Data Structures And Algo Using Python Assignment 3 Answers [Jan 2022]

All questions carry equal weightage. All Python code is assumed to be executed using Python3. You may submit as many times as you like within the deadline. Your final submission will be graded.

Note:

• If the question asks about a value of type list, remember to enclose your answer in square brackets and use commas to separate list items.

Q1. Write three Python functions as specified below. Paste the text for all three functions together into the submission window. Your function will be called automatically with various inputs and should return values as specified. Do not write commands to read any input or print any output.

• You may define additional auxiliary functions as needed.
• In all cases you may assume that the value passed to the function is of the expected type, so your function does not have to check for malformed inputs.
• For each function, there are normally some public test cases and some (hidden) private test cases.
• “Compile and run” will evaluate your submission against the public test cases.
• “Submit” will evaluate your submission against the hidden private test cases. There are 10 private test cases, with equal weightage. You will get feedback about which private test cases pass or fail, though you cannot see the actual test cases.
• Ignore warnings about “Presentation errors”.
1. Define a Python function remdup(l) that takes a nonempty list of integers l and removes all duplicates in l, keeping only the first occurrence of each number. For instance:
2. Write a Python function sumsquare(l) that takes a nonempty list of integers and returns a list [odd,even], where odd is the sum of squares all the odd numbers in l and even is the sum of squares of all the even numbers in l.
3. A two dimensional matrix can be represented in Python row-wise, as a list of lists: each inner list represents one row of the matrix. For instance, the matrix

Code:-

``````def remdup(l):
L=[]
for i in l:
if i not in L:
L.append(i)
return(L)

def sumsquare(l):
odd_sum=0
even_sum=0
for a in l:
if a%2!=0:
odd_sum+=a*a
else:
even_sum+=a*a
return([odd_sum,even_sum])

def transpose(m):
ans=list()
for i in range(len(m)):
a=[]
for j in range(len(m)):
a.append(m[j][i])
ans.append(a)
return(ans)``````