Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

** MAXIMUM TERMINALS ACTIVE. TRY AGAIN LATER **


devel / comp.lang.python / Re: code confusion

SubjectAuthor
* code confusionTola Oj
`* Re: code confusionDennis Lee Bieber
 `- Re: code confusionAvi Gross

1
code confusion

<mailman.106.1650008490.20749.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17844&group=comp.lang.python#17844

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ojomoolu...@gmail.com (Tola Oj)
Newsgroups: comp.lang.python
Subject: code confusion
Date: Fri, 15 Apr 2022 08:41:20 +0100
Lines: 16
Message-ID: <mailman.106.1650008490.20749.python-list@python.org>
References: <CAD9v3s=Zz165CknTu7ZS6LRWqqmCtdL=ymh3QpmuaqAfC3aVgw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de 62Lav5XFXDVUu0BPRJGVyQKuWJTG9AYZJSxBh0FOw+mw==
Return-Path: <ojomooluwatolami675@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=EEvKEVIo;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.185
X-Spam-Level: *
X-Spam-Evidence: '*H*': 0.64; '*S*': 0.00; 'used.': 0.07; 'question,':
0.16; 'subject:code': 0.16; 'to:addr:python-list': 0.20; 'code':
0.23; 'discussion': 0.25; 'question': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'there': 0.33; "didn't": 0.34; 'mean':
0.34; 'received:google.com': 0.34; 'from:addr:gmail.com': 0.35;
'functions': 0.36; 'using': 0.37; 'received:209.85': 0.37;
'could': 0.38; 'received:209': 0.39; 'received:209.85.208': 0.39;
'use': 0.39; 'methods': 0.39; 'chat': 0.61; '8bit%:17': 0.63;
'well': 0.65; '8bit%:21': 0.68; 'major': 0.78; 'struggle': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:from:date:message-id:subject:to;
bh=bWqUxmGCEyg713yry6J8sI2J9xLisRK7NbWBJZPp45Y=;
b=EEvKEVIoT5vsu/GUuQgx926+LiWJMeKPAMoMxQqGK7zJ97i/yJK1HTpIhyvyeTQaEV
coRz+BmUVXOOUbur608QBIEHNti12CtDB4jrNdqGLsW46PnHz3IH1DPiQzU3mIocY/jJ
JcSlfSC03SBpBzeUtf7NYk1WEe7vMqNrVc5CafiIHLpgrX7mieOdeCywXVn73Y7gWPVn
eXXr2ug9dcW+E0Bb8Oy1F6zYjseo+H/UVFcUTzBvhzESeNayiXZk6rNd6BVDY3Mzabc9
L1T5DcqoxDXvKj6oV//WS5ncPn/jSxQ+BBf01orPjJGz/vSh5ZWCbo+P3yHvvW+IS3PN
q0+w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
bh=bWqUxmGCEyg713yry6J8sI2J9xLisRK7NbWBJZPp45Y=;
b=ZNl7wTQLrvtchSFq33FzwU2o4sM8afmW8wNi5TXThmuXE0ydISrbKvQM8tR3Zg5os0
L1dBFOS9ITZQFitVUf2s+zYd3mTrzlWWWLBY0U7iI1t60lwGi/ICj53IrL7EI5r9R0SC
AJuZCcYoZcTp7l0JulgTtS7ch2MbE0TduhRQdx3emaOexNEP/HrVH2a/WprLKD+eP5IW
UgL4Y8dazlWlbvPzqqgUz9QoG+dAgjoK3oap+ukT7PPzDyaFTwbqZguKFaNDuuO4zyk+
VmaX2EYO63SqcrUMedDZ9JQ9Hx46C4VTGyWjtiOL+zk+czmblhKCJgQMcKEEEx6xAYym
Jl3g==
X-Gm-Message-State: AOAM532/5vZ/t9vV6FqGa7oysaAqGoqnnhI5qSFUvDQCgUpg2r0FMHT9
Z/F7T2H9kBkolO6LTV1GasOpqHl9FsXlffJZKHMV1q7LnB0=
X-Google-Smtp-Source: ABdhPJyNN5qx2VUqcjKYlXKRsHZhMZk9h0iwCszEQ5r/ptUulvQHb4ZwPE5itPLYm2fZh8sj3a6KNS86UKOe8j01StM=
X-Received: by 2002:a2e:90d6:0:b0:246:e44:bcf6 with SMTP id
o22-20020a2e90d6000000b002460e44bcf6mr3671744ljg.501.1650008488835; Fri, 15
Apr 2022 00:41:28 -0700 (PDT)
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAD9v3s=Zz165CknTu7ZS6LRWqqmCtdL=ymh3QpmuaqAfC3aVgw@mail.gmail.com>
 by: Tola Oj - Fri, 15 Apr 2022 07:41 UTC

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

Re: code confusion

<9jcj5h1jumpf3sauil11540pqs27c6qnp7@4ax.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17856&group=comp.lang.python#17856

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 15 Apr 2022 13:31:33 -0500
From: wlfr...@ix.netcom.com (Dennis Lee Bieber)
Newsgroups: comp.lang.python
Subject: Re: code confusion
Date: Fri, 15 Apr 2022 14:31:33 -0400
Organization: IISS Elusive Unicorn
Message-ID: <9jcj5h1jumpf3sauil11540pqs27c6qnp7@4ax.com>
References: <CAD9v3s=Zz165CknTu7ZS6LRWqqmCtdL=ymh3QpmuaqAfC3aVgw@mail.gmail.com> <mailman.106.1650008490.20749.python-list@python.org>
User-Agent: ForteAgent/8.00.32.1272
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 103
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-fo5fsYSJ580G/IxGBb0XKZfEeVR+tBYF4R9+ovV14n0U5k4UiEhK+rCaBdlSSctfBZ/xIvAjjf0YjmW!YI6s/OyskQ/1Mm/aUMDElhV4/qh1q+PoSoA8XsbdCY3NMbTKOEJyi68Cg+JBhXrs3VKxKXqE
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 4570
 by: Dennis Lee Bieber - Fri, 15 Apr 2022 18:31 UTC

On Fri, 15 Apr 2022 08:41:20 +0100, Tola Oj <ojomooluwatolami675@gmail.com>
declaimed the following:

>i = int(input())

Obtain a single /integer/ from stdin -- note: any extraneous characters
on the input line will result in a failure to convert from textual
representation to internal/binary integer

>lis = list(map(int,input().strip().split()))[:i]

Obtain a line from stdin containing space separated /integer/
representations. Split the line at the spaces. Convert each "word" to
internal/binary integer. Keep up to at most "i" integers. Note that the
position of the [:i] could be at
... .split()[:i]
The difference being that the provided code is converting all "words" on
the input into integers and then keeping the first "i"; putting the [:i]
after .split() means only the first "i" words are kept, and hence only that
many need to be converted to integer.

>z = max(lis)

Determine largest value in the list of integers

>while max(lis) == z:
>lis.remove(max(lis))

WHILE the largest value in the (current) list matches the initially
determined maximum value... remove that value from the list.

Rather than repeat "max(lis)" in the .remove() invocation, just pass it
"z" (the WHILE has already confirmed that the maximum "z" is found in the
list, so why recompute the maximum).

Note: Python indentation is significant -- the above .remove() line
needs to be indented. Presuming your code was properly indented please find
a posting client that doesn't reformat leading indentation.

>
>print (max(lis))
>

Display the new list maximum value after removing all instances of the
initial maximum value.

>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

Learn the contents of the Library Reference Manual -- you don't need to
memorize it all, but should at least know the major groupings...

https://docs.python.org/3/library/stdtypes.html#common-sequence-operations

> 2. is there
>another i could write this code using if statement?

There are many ways to rewrite that...

UNTESTED

i = int(input("How many integers are to be considered?"))
ls = [int(wd) for wd in input(
"enter space separated integers"
).split()[:i]]
maximum = max(ls)
while maximum in ls:
ls.remove(maximum)
print(ls)

Remove the first line, and the [:i], and the code will happily process
for however many integers are provided on the input line.

The while/remove loop can be replaced with

ls = [itm for itm in ls if itm != maximum]

which only requires one pass through the list; while/remove has to scan the
list to see if maximum is in it, then has to scan it a second time to for
the .remove() to find where in the list it is found.

Or...

for _ in range(ls.count(maximum)):
ls.remove(maximum)

where _ is a "junk/temp" value that we don't care about -- we only want to
loop once for EACH maximum value

Or...

while maximum in ls:
del ls[ls.index(maximum)]

--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/

Re: code confusion

<mailman.115.1650056299.20749.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17861&group=comp.lang.python#17861

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: avigr...@verizon.net (Avi Gross)
Newsgroups: comp.lang.python
Subject: Re: code confusion
Date: Fri, 15 Apr 2022 20:58:15 +0000 (UTC)
Lines: 152
Message-ID: <mailman.115.1650056299.20749.python-list@python.org>
References: <CAD9v3s=Zz165CknTu7ZS6LRWqqmCtdL=ymh3QpmuaqAfC3aVgw@mail.gmail.com>
<mailman.106.1650008490.20749.python-list@python.org>
<9jcj5h1jumpf3sauil11540pqs27c6qnp7@4ax.com>
<1355735908.167920.1650056295834@mail.yahoo.com>
Reply-To: Avi Gross <avigross@verizon.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de l47N0Jjg05gLVBUBTs7ccQQct6k18Rau92JaogDghtOw==
Return-Path: <avigross@verizon.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=verizon.net header.i=@verizon.net header.b=EtsLY1vT;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.015
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'looks': 0.02; '2022':
0.05; 'containing': 0.05; 'variable': 0.05; 'loop': 0.07;
'matches': 0.07; 'modules': 0.07; 'used.': 0.07; 'breaks': 0.09;
'converting': 0.09; 'fit.': 0.09; 'instances': 0.09; 'like,':
0.09; '&gt;': 0.14; 'questions.': 0.14; 'url:mailman': 0.15;
'confusion': 0.16; 'determining': 0.16; 'exception.': 0.16;
'found.': 0.16; 'indentation': 0.16; 'integer': 0.16; 'intuitive':
0.16; 'loops': 0.16; 'nested': 0.16; 'ones.': 0.16; 'reformat':
0.16; 'rewrite': 0.16; 'skip:> 20': 0.16; 'subject:code': 0.16;
'textual': 0.16; 'usual,': 0.16; 'python': 0.16; 'larger': 0.17;
'to:addr:python-list': 0.20; 'all,': 0.20; 'input': 0.21;
'languages': 0.22; 'fri,': 0.22; 'instructions': 0.22; 'way.':
0.22; 'code': 0.23; 'list,': 0.24; 'to:name:python-
list@python.org': 0.24; 'anything': 0.25; 'skip:- 10': 0.25; 'url-
ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24': 0.25;
'discussion': 0.25; 'url:listinfo': 0.25; 'url-ip:188.166/16':
0.25; 'space': 0.26; 'library': 0.26; 'keeping': 0.28; 'suggest':
0.28; 'wrong': 0.28; 'asked': 0.29; 'it,': 0.29; 'putting': 0.31;
'url-ip:188/8': 0.31; "doesn't": 0.32; 'question': 0.32;
'answers': 0.32; 'end.': 0.32; 'obtain': 0.32; 'rapidly': 0.32;
'split': 0.32; 'unless': 0.32; 'but': 0.32; 'there': 0.33; 'mean':
0.34; 'requires': 0.34; 'header:In-Reply-To:1': 0.34; 'complex':
0.35; 'words': 0.35; 'yes,': 0.35; 'display': 0.36; 'functions':
0.36; 'using': 0.37; 'hard': 0.37; 'could': 0.38; 'means': 0.38;
'two': 0.39; 'quite': 0.39; 'least': 0.39; 'single': 0.39;
'valid': 0.39; 'list': 0.39; 'use': 0.39; 'methods': 0.39;
'people,': 0.40; 'learn': 0.40; 'something': 0.40; 'want': 0.40;
'should': 0.40; 'reference': 0.60; 'chat': 0.61; 'initial': 0.61;
'skip:o 10': 0.61; 'above': 0.62; 'from:': 0.62; 'to:': 0.62;
'here': 0.62; 'simply': 0.63; 'once': 0.63; 'leading': 0.63;
'pass': 0.64; 'skip:r 20': 0.64; 'clear': 0.64; 'number,': 0.64;
're:': 0.64; 'verified': 0.64; 'your': 0.64; 'well': 0.65;
'numbers': 0.67; 'maximum': 0.67; 'choose': 0.67; 'following:':
0.69; '2nd': 0.70; 'del': 0.70; 'manual': 0.70; 'care': 0.71;
'note:': 0.71; 'sent:': 0.78; 'significant': 0.78; 'major': 0.78;
'header:Reply-To:1': 0.79; 'confirmed': 0.81; 'position': 0.81;
'client': 0.82; 'largest': 0.84; 'reasons': 0.84; '"enter': 0.84;
'characters': 0.84; 'converted': 0.84; 'struggle': 0.84;
'that...': 0.84; 'want.': 0.84; 'line,': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verizon.net; s=a2048;
t=1650056297; bh=33wgmxB7mkguAiHdbFP80QWBJF5zzOK4CfMFnG1o+P8=;
h=Date:From:Reply-To:To:In-Reply-To:References:Subject:From:Subject:Reply-To;
b=EtsLY1vTfO0H3z1yWsfNn/u9SBEn81c6qnZmotbX6vR0YaOufKAPW7S264i1zU1Ht7iEYrH8DeMCks52YyMZYmi1sCGXspFgk6N0PCCgiKCNEijtHNwsYS06Gb9+FWYn/RaLrmiMW6hjVqI0QnFW68mCCjgDZ6vBDqA+U1nAhe6TPS9TkimDTqa8pJgmKLct1Y0xoj4CRrXQPKU26TcXtcrj4XJlEXOfHqrUu5YCTRZ2u8pHqPshiSlwD30oU6reAIZxhsR+1HnbB7Yi1uWeHw4L01op8Mw1tYJNzqQkDw6DPz0PUlDhQyeECjMfa6AyGeWhds8PsqprzqDezwTugA==
X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048;
t=1650056297; bh=+vMo7fGrCvDAI1XiuVJjc5gq43Eli0X2dSR1wROKgY1=;
h=X-Sonic-MF:Date:From:To:Subject:From:Subject;
b=c1EcC77y9eXUQvxC0dLFvCvOxtEhIUb5W7Z9X2aaxMvbXIGaJUrspKZlTJhdYGn/+Ji/wAZJt7uynA9SI6GPxc8BndBjKcqKA7yA8jkhPRlsHOqJeXG1XU7myq4FfL934NF4X2h/5fGkpYpIIvMTL2UQcLyjaA/GDLbHabdKXtAxL+BrW9XnzUEvY+yDrMZd2auOYFUfpN3DeaUpim0ihaDoaaDdIMyWrLFnOEHnUH6cBIQAr+7iWIts6W4Ll/ZAtpg1tnVdJK/95VX3r4b6oS60C1rhAOKq4d0GXIDTxTKaxYFdnArt11C7t/ESHhpqci1iAvGapLwiSoTWjEWn2A==
X-YMail-OSG: gIE6DQkVM1lyP49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uV8Mb3ZBAEVEa5OoyNviU8N8ODoTzZwSt1KW.4WfClznsZB6p4zqytYth
LoBOJJUzn3VgTDbDEeTTBIiNIIO2xA23ds.6PITXrCACarSP51rMiYOc5qAArFkHH3wFVeQrrfYm
BzCMQ8hEL_P5LGHte9ZtRb2Crk2smYjD.k0_CPQ4-
X-Sonic-MF: <avigross@verizon.net>
In-Reply-To: <9jcj5h1jumpf3sauil11540pqs27c6qnp7@4ax.com>
X-Mailer: WebService/1.1.20048 aolwebmail
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <1355735908.167920.1650056295834@mail.yahoo.com>
X-Mailman-Original-References: <CAD9v3s=Zz165CknTu7ZS6LRWqqmCtdL=ymh3QpmuaqAfC3aVgw@mail.gmail.com>
<mailman.106.1650008490.20749.python-list@python.org>
<9jcj5h1jumpf3sauil11540pqs27c6qnp7@4ax.com>
 by: Avi Gross - Fri, 15 Apr 2022 20:58 UTC

As usual, without very clear and precise instructions and parameters, the answers may not quite fit.
It looks like you are asked two and only two questions.
The first is asking how many numbers you want. 
Before continuing, you need to make sure that is a valid number as many answer will throw an exception.
The next line, complex as it is, asks for one long answer and does not check anything and breaks rapidly unless you use just normal integer representation. Yes, it ignores any entry after the "i"th but if you want valid entries, you might want to evaluate them in a loop perhaps one at a time and keep going till you have 'i" valid ones.
I do suggest you not use the variable name of "i" for many reasons as modern languages allow more meaningful names like, well, "n"!
I understand using i, j, k in some nested loops but here I would haveused something like howMany and verified the number was an integer larger than 0.
As for getting the second largest number, there is nothing wrong with determining it the hard way. Of course for some people, it is more intuitive to sort the uniqued data and simply choose the 2nd entry from the end. Some python modules allow you tosee the ranks of various entries and you can simply choose the one of second rank. 
But if this is HW, you are being asked to do things the old-fashioned way! LOL!

-----Original Message-----
From: Dennis Lee Bieber <wlfraed@ix.netcom.com>
To: python-list@python.org
Sent: Fri, Apr 15, 2022 2:31 pm
Subject: Re: code confusion

On Fri, 15 Apr 2022 08:41:20 +0100, Tola Oj <ojomooluwatolami675@gmail.com>
declaimed the following:

>i = int(input())

    Obtain a single /integer/ from stdin -- note: any extraneous characters
on the input line will result in a failure to convert from textual
representation to internal/binary integer

>lis = list(map(int,input().strip().split()))[:i]

    Obtain a line from stdin containing space separated /integer/
representations. Split the line at the spaces. Convert each "word" to
internal/binary integer. Keep up to at most "i" integers. Note that the
position of the [:i] could be at
            ... .split()[:i]
The difference being that the provided code is converting all "words" on
the input into integers and then keeping the first "i"; putting the [:i]
after .split() means only the first "i" words are kept, and hence only that
many need to be converted to integer.

>z = max(lis)

    Determine largest value in the list of integers

>while max(lis) == z:
>lis.remove(max(lis))

    WHILE the largest value in the (current) list matches the initially
determined maximum value... remove that value from the list.

    Rather than repeat "max(lis)" in the .remove() invocation, just pass it
"z" (the WHILE has already confirmed that the maximum "z" is found in the
list, so why recompute the maximum).

    Note: Python indentation is significant -- the above .remove() line
needs to be indented. Presuming your code was properly indented please find
a posting client that doesn't reformat leading indentation.

>
>print (max(lis))
>

    Display the new list maximum value after removing all instances of the
initial maximum value.

>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

    Learn the contents of the Library Reference Manual -- you don't need to
memorize it all, but should at least know the major groupings...

https://docs.python.org/3/library/stdtypes.html#common-sequence-operations

>                                                        2. is there
>another i could write this code using if statement?

    There are many ways to rewrite that...

UNTESTED

i = int(input("How many integers are to be considered?"))
ls = [int(wd) for wd in input(
                "enter space separated integers"
                ).split()[:i]]
maximum = max(ls)
while maximum in ls:
    ls.remove(maximum)
print(ls)

    Remove the first line, and the [:i], and the code will happily process
for however many integers are provided on the input line.

    The while/remove loop can be replaced with

ls = [itm for itm in ls if itm != maximum]

which only requires one pass through the list; while/remove has to scan the
list to see if maximum is in it, then has to scan it a second time to for
the .remove() to find where in the list it is found.

    Or...

for _ in range(ls.count(maximum)):
    ls.remove(maximum)

where _ is a "junk/temp" value that we don't care about -- we only want to
loop once for EACH maximum value

    Or...

while maximum in ls:
    del ls[ls.index(maximum)]

--
    Wulfraed                Dennis Lee Bieber        AF6VN
    wlfraed@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/
--
https://mail.python.org/mailman/listinfo/python-list

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor