#π Problem with timeit list remove
22 messages Β· Page 1 of 1 (latest)
@frozen steeple
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.
!ti
l = [0, 1, 2, 3]
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
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
:white_check_mark: Your 3.12 timeit job has completed with return code 0.
10000000 loops, best of 5: 36 nsec per loop
it runs multiple times
so if you only have 1 setup list, it's gonna run out
oh, i thought the setup was per-run
or, rather, the element is gonna disappear
i wonder if there's a way to isolate just the remove?
!ti
l = [0, 1, 2, 3]
l.remove(0)
:white_check_mark: Your 3.12 timeit job has completed with return code 0.
2000000 loops, best of 5: 166 nsec per loop
!ti
l = [0, 1, 2, 3]
:white_check_mark: Your 3.12 timeit job has completed with return code 0.
2000000 loops, best of 5: 114 nsec per loop
i see
i guess subtract the time of list creation from the time of the combined code?
good enough for me π thank you
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.