Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def print _ list ( lst ) : print ( ' , ' . join ( lst ) ) # 2 def start _ with

def print_list(lst):
print(','.join(lst))
# 2
def start_with_count(lst, char):
return sum(1 for item in lst if item.startswith(char))
# 3
def double_list(lst):
doubled_list =[]
for car in lst:
doubled_list.extend([car, car])
return doubled_list
# 4
def print_reversed(lst):
reversed_list =[]
for i in range(len(lst)-1,-1,-1):
reversed_list.append(lst[i])
print(reversed_list)
# 5
def rotate_list(lst):
rotated = lst[1:]+[lst[0]]
return rotated
# 6
def cal_avg(lst):
total_length = sum(len(item) for item in lst)
return total_length / len(lst)
if __name__=="__main__":
car_list =['Chevrolet', 'Cadillac', 'Buick', 'GMC', 'Ford', 'Jeep', 'Dodge', 'Tesla', 'Austin']
print('Here is the list:')
print_list(car_list)
print('The number of cars start with C is:', start_with_count(car_list, 'C'))
print('The list doubled: ')
print(double_list(car_list))
print('The list reversed:')
print_reversed(car_list)
print('The list after a right rotate:')
print(rotate_list(car_list))
print('The average length of the list items is: %.2f'% cal_avg(car_list))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions