Advertisement
Guest User

pylon

a guest
Mar 26th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. # Question 7
  2.  
  3. def unique_list(l):
  4.   x = []
  5.   for a in l:
  6.     if a not in x:
  7.       x.append(a)
  8.   return x
  9.  
  10. print(unique_list([1,2,3,3,3,3,4,5]))
  11.  
  12. # Question 8
  13.  
  14. my_list = [5, 3, 7, 9, 2, 5, 5, 3, 10, 8, 7]
  15.  
  16. print('The list is {0}'.format(my_list))
  17.  
  18. def backways(alist):
  19.   return alist[::-1]
  20.  
  21. print(backways(my_list)
  22.  
  23.  
  24. # Question 9
  25.  
  26. my_list = [5, 3, 7, 9, 2, 5, 5, 3, 10, 8, 7]
  27.  
  28. print('The list is {0}'.format(my_list))
  29.  
  30. def sum_list(alist):
  31.   total = 0
  32.   for i in range(len(alist)):
  33.     total += alist[i]
  34.   return total
  35.  
  36. print(sum_list(my_list))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement