Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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]]
- for w in lists:
- lst = w
- a = float ("-inf")
- for x in range (0, len (lst)):
- b = lst [x]
- if (b > a):
- a = b
- c = x
- z = lst
- print ("The list is:",z)
- print ("The highest value is: " , a)
- print ("The position is:", c+1)
- Out:
- The list is: [32, 45, 56, 554, 12, 33]
- The highest value is: 554
- The position is: 4
- Out:
- The list is: [1,-3,5,2,6,11,78,5,-345,-3,6,98,-5,0]
- The second highest value is: 98
- The position is: 12
- >>> lst = [1,-3,5,2,6,11,78,5,-345,-3,6,98,-5,0]
- >>> sorted(lst)
- [-345, -5, -3, -3, 0, 1, 2, 5, 5, 6, 6, 11, 78, 98]
- >>>
- >>> second_most = sorted(lst)[-2]
- >>> second_most
- 78
- >>>
- >>> lst.index(78)
- 6
- >>>
- import numpy as np
- list = [32, 45, 56, 554, 12, 33]
- inds = np.argsort(list)
- print(list[inds[-2]])
- # outputs: 56
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement