38.1.1. Understanding List functions
data = input("data: ")
list1 = data.split(",")
#find the length
size = len(list1)
#convert the elements into integer type
for i in range(size):
list1[i] = int(list1[i])
print("length:", size)#print the length of list1
print("list enumerate:", list(enumerate(list1)))#print the enumerate of list1
print("max:", max(list1))#print the maximum value of list1
print("min:", min(list1))#print the minimum value of list1
print("list:", sorted(list1))#print the sorted list
38.1.2. Write a Program to print the difference between maximum and minimum values of a List
x = input("data: ").split(',')
print("min:",min(x))
print("max:",max(x))
print("difference:", int(max(x))-int(min(x)))
38.1.3. Write a program to find the sum of elements of a given integer List
a = input("data: ").split(',')
l = []
for i in a:
l.append(int(i))
print('sum:', sum(l))
38.1.4. Write a program to print the sum of squares of elements of a List
#write your code here
a=input("data: ").split(",")
l=[]
for i in a:
l.append(int(i))
print("list:",l)
print("sum:", sum(l))
l2=[]
for i in l:
l2.append(i**2)
print("squares:",l2)
print("sum of squares:", sum(l2))
38.1.5. Write a program to print a dictionary using two given Lists
a = input("data1: ").split(',')
b = input("data2: ").split(',')
if len(a) == len(b):
c = "{"
for i in range(len(a)):
c+="'"+a[i]+"'"+":"+"'"+b[i]+"'"+","
c=c[:-1]
c+='}'
print(c)
else:
print("lists are different lengths")
38.1.6. Write a program to print a list created from the absolute differences of elements in the corresponding positions of two equal sized lists.
#write your code here
a = input("data1: ").split(',')
l = []
for i in a:
l.append(int(i))
b = input("data2: ").split(',')
m = []
for i in b:
m.append(int(i))
if len(l) == len(m):
if m[0]==1:
n = [m[i]*10 for i in range(len(m))]
else:
n=m
print(n)
else:
print("lists are different lengths")