On 15/04/2022 19.41, Tola Oj wrote: > i = int(input()) > lis = list(map(int,input().strip().split()))[:i] > z = max(lis) > while max(lis) == z: > lis.remove(max(lis)) > > print (max(lis)) > > this is an answer to a question from the discussion chat in hackerrank. i > didn't know the answer so i found an answer that fitted well to the > question, however i struggle to understand the use of some of the methods > and functions the person has used. my major questions are: 1. what does > "[:i]" mean > 2. is there > another i could write this code using if statement? > thank you
It is taking a slice from the list: https://docs.python.org/3/glossary.html#term-slice More explanation: https://docs.python.org/3/tutorial/introduction.html?highlight=slice -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list