Liste des Groupes | Revenir à cl c |
On 15.06.2024 06:45, DFS wrote:Python bytecodeOn 6/14/2024 11:56 PM, Keith Thompson wrote:Given what Keith suggested, and assuming N is an integer, wouldn't itDFS <nospam@dfs.com> writes:>>>
After casting i to an int before any array addressing, // works.
I'm surprised you needed to convert i to an int. I would think that
just replacing nums[i/2] by nums[i//2] would do the trick,
as long as i always has an int value (note Python's dynamic typing).
If i is acquiring a float value, that's probably a bug, given the name.
I spotted the issue. Just prior to using i for array addressing I said:
i = N/2.
>
The fix is set i = int(N/2)
be more sensible to use the int division operator '//' and just write
i = N // 2 ? I mean, why do a float division on integer operands and
then again coerce the result to int again?
Les messages affichés proviennent d'usenet.