#πŸ”’ Problem with timeit list remove

22 messages Β· Page 1 of 1 (latest)

frozen steeple
#

I'm having a problem using timeit to benchmark list.remove. I create a list in the setup, but it can't find values in the list while running the test.

mellow vergeBOT
#

@frozen steeple

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

frozen steeple
#

!ti

l = [0, 1, 2, 3]
l.remove(0)
mellow vergeBOT
# frozen steeple !ti ```python l = [0, 1, 2, 3] ``` ```python l.remove(0) ```

:x: Your 3.12 timeit job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "/snekbin/python/3.12/lib/python3.12/timeit.py", line 330, in main
003 |     number, _ = t.autorange(callback)
004 |                 ^^^^^^^^^^^^^^^^^^^^^
005 |   File "/snekbin/python/3.12/lib/python3.12/timeit.py", line 226, in autorange
006 |     time_taken = self.timeit(number)
007 |                  ^^^^^^^^^^^^^^^^^^^
008 |   File "/snekbin/python/3.12/lib/python3.12/timeit.py", line 180, in timeit
009 |     timing = self.inner(it, self.timer)
010 |              ^^^^^^^^^^^^^^^^^^^^^^^^^^
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/RHFGMOKCO3JDMLTPPDF53TEDXI

frozen steeple
#

the exception is ValueError: list.remove(x): x not in list

#

meanwhile, checking in works fine

#

!ti

l = [0, 1, 2, 3]
0 in l
mellow vergeBOT
onyx tangle
#

so if you only have 1 setup list, it's gonna run out

frozen steeple
#

oh, i thought the setup was per-run

onyx tangle
frozen steeple
#

i wonder if there's a way to isolate just the remove?

onyx tangle
#

!ti

l = [0, 1, 2, 3]
l.remove(0)
mellow vergeBOT
onyx tangle
#

!ti

l = [0, 1, 2, 3]
mellow vergeBOT
frozen steeple
#

i see

onyx tangle
#

i guess subtract the time of list creation from the time of the combined code?

frozen steeple
#

good enough for me πŸ˜‚ thank you

mellow vergeBOT
#
Python help channel closed using Discord native close action

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.