Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. 1. Create a function that returns the average of a list of numbers
  2.  
  3. def average(my_list):
  4. # your code
  5.  
  6.  
  7. print(average([1 , 2 , 3, 4 , 5])) --> 3
  8.  
  9.  
  10. 2. Create a function that returns the second maximum number of a list
  11.  
  12. def sec_maximum(my_list):
  13. # your code
  14.  
  15.  
  16. print(sec_maximum([2 , 1 , 5, 2 , 3])) --> 3
  17.  
  18.  
  19. 2. Create a function that returns the second maximum number of a list
  20.  
  21. def sec_maximum(my_list):
  22. # your code
  23.  
  24.  
  25. print(sec_maximum([2 , 1 , 5, 2 , 3])) --> 3
  26.  
  27. 3. Write a Python function that takes two lists and prints True if they have at least one common member and False otherwise.
  28.  
  29. def common(list_1, list_2):
  30. # your code
  31.  
  32.  
  33. print(common([2 , 1 , 5], [3 , 4 , 1])) --> True
  34. print(common([2 , 1 , 5], [3 , 4 , 6])) --> True
  35.  
  36. 4. Write a Python function to convert a string of numbers separated by comma eg '1,2,3,4' to a list of numbers eg [1, 2, 3 , 4].
  37.  
  38. def get_list(my_string):
  39. # your code
  40.  
  41.  
  42. print(get_list('1,2,3,4')) --> [1 , 2 , 3 , 4]
  43.  
  44.  
  45. 5. Write a Python function that returns a specified list after removing even numbers from it.
  46.  
  47. def remove_evens(my_list):
  48. # your code
  49.  
  50.  
  51. print(remove_evens([2 , 1 , 5, 2 , 3])) --> [1 , 5 , 3]
  52.  
  53.  
  54. 6. Write a Python function to count the number of strings where the string length is 2 or more and the first and last character are same from a given list of strings.
  55.  
  56. def good_strings(my_list):
  57. # your code
  58.  
  59.  
  60. print(good_strings(['abc', 'xyz', 'aba', '1221'])) --> 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement