feat: Initial commit
This commit is contained in:
79
Laboratorio9/esercizio1.py
Normal file
79
Laboratorio9/esercizio1.py
Normal file
@@ -0,0 +1,79 @@
|
||||
def scambiaEstremi(a: list):
|
||||
c = a[0]
|
||||
a[0] = a[-1]
|
||||
a[-1] = c
|
||||
|
||||
|
||||
def ruotaDestra(a: list):
|
||||
c = a.pop()
|
||||
a.insert(0, c)
|
||||
|
||||
|
||||
def azzeraPari(a: list):
|
||||
for i in range(0, len(a), 2):
|
||||
a[i] = 0
|
||||
|
||||
|
||||
def maxL(a: list):
|
||||
b = a.copy()
|
||||
|
||||
for i in range(1, len(a) - 1):
|
||||
b[i] = max(a[i-1], a[i+1])
|
||||
|
||||
|
||||
def rimuoviCentrale(a: list):
|
||||
if len(a) % 2 == 0:
|
||||
mi = len(a) // 2
|
||||
a.pop(mi - 1)
|
||||
a.pop(mi - 1)
|
||||
return
|
||||
|
||||
mi = len(a) // 2
|
||||
a.pop(mi - 1)
|
||||
|
||||
|
||||
def pariInizio(a: list):
|
||||
x = 0
|
||||
for i in range(0, len(a), 2):
|
||||
a.insert(x, a.pop(i))
|
||||
x += 1
|
||||
|
||||
|
||||
def secondMax(a: list):
|
||||
if a[0] > a[1]:
|
||||
fmax = a[0]
|
||||
smax = a[1]
|
||||
else:
|
||||
fmax = a[1]
|
||||
smax = a[0]
|
||||
|
||||
for i in range(2, len(a)):
|
||||
if a[i] > fmax:
|
||||
smax = fmax
|
||||
fmax = a[i]
|
||||
elif a[i] > smax:
|
||||
smax = a[i]
|
||||
|
||||
return smax
|
||||
|
||||
|
||||
def isListOrdered(a: list):
|
||||
b = sorted(a)
|
||||
|
||||
for i in range(len(a)):
|
||||
if a[i] != b[i]:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def twoAdiacentDuplicates(a: list):
|
||||
for i in range(0, len(a) - 1):
|
||||
if i[0] == i[1]:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def twoDuplicates(a: list):
|
||||
return twoAdiacentDuplicates(sorted(a))
|
||||
Reference in New Issue
Block a user