Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. lists = [[1,-3,5,2,6,11,78,5,-345,-3,6,98,-5,0],[1,2,3,4,5,6,7,6,5,4,4],[-435,-64,-4,-6,-45,-8,-98,-7,-8],[32,45,56,554,12,33]]
  2. for w in lists:
  3. lst = w
  4. a = float ("-inf")
  5. for x in range (0, len (lst)):
  6. b = lst [x]
  7. if (b > a):
  8. a = b
  9. c = x
  10. z = lst
  11. print ("The list is:",z)
  12. print ("The highest value is: " , a)
  13. print ("The position is:", c+1)
  14.  
  15. Out:
  16. The list is: [32, 45, 56, 554, 12, 33]
  17. The highest value is: 554
  18. The position is: 4
  19.  
  20. Out:
  21. The list is: [1,-3,5,2,6,11,78,5,-345,-3,6,98,-5,0]
  22. The second highest value is: 98
  23. The position is: 12
  24.  
  25. >>> lst = [1,-3,5,2,6,11,78,5,-345,-3,6,98,-5,0]
  26.  
  27. >>> sorted(lst)
  28. [-345, -5, -3, -3, 0, 1, 2, 5, 5, 6, 6, 11, 78, 98]
  29. >>>
  30. >>> second_most = sorted(lst)[-2]
  31. >>> second_most
  32. 78
  33. >>>
  34. >>> lst.index(78)
  35. 6
  36. >>>
  37.  
  38. import numpy as np
  39. list = [32, 45, 56, 554, 12, 33]
  40. inds = np.argsort(list)
  41. print(list[inds[-2]])
  42. # outputs: 56
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement