code confusion
Chris Angelico
rosuav at gmail.com
Fri Apr 15 03:48:26 EDT 2022
On Fri, 15 Apr 2022 at 17:42, Tola Oj <ojomooluwatolami675 at gmail.com> 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?
If you don't understand the code, don't submit it :) You should create
your own code for hackerrank.
I'll just give very very broad hints:
1) It's slicing. Play around with it in the interactive interpreter
and see what it does with different inputs.
2) Yes. You can always write code with an if statement. What are you
actually trying to accomplish though?
ChrisA
More information about the Python-list
mailing list