In: Computer Science
Homework 5: Lists
Please show code in Pycharm
The task is to create the following three functions to demonstrate techniques for working with lists:
1.def greatestPair(x):
if len(x)==0:
return None
elif len(x)==1:
return 0
(a,b) = (x[0],x[1])
sol = 0
for i in range(len(x)-1):
if
max(a,b)>max(x[i],x[i+1]) and
min(a,b)>min(x[i],x[i+1]):
(a,b) = (x[i],x[i+1])
sol = i
return i
2. def isSorted(x):
if(x==sorted(x) or
x==sorted(x,reverse=True)):
return True
else:
return False
3. def intersection(x,y):
lis = []
for i in x:
if i in y and i not in
lis:
lis.append(i)
return lis