[issue45579] [list.append(i) for i in list] causes high resources usage

2021-10-23 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45579] [list.append(i) for i in list] causes high resources usage

2021-10-23 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

It is expected behavior. Your code is equivalent to:

_result = []
for i in your_list:
_result.append(your_list.append(i))

which is equivalent to:

_result = []
_j = 0
while _j < len(your_list):
i = your_list[_j]
_result.append(your_list.append(i))
_j += 1

It is an infinite loop (because len(your_list) is increased after 
your_list.append(i)), and two lists grow with every iteration.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45579] [list.append(i) for i in list] causes high resources usage

2021-10-22 Thread Spencer Brown


Spencer Brown  added the comment:

This is intentional behaviour, you actually created an infinite loop. When you 
iterate over a list, all Python does is track the current index through the 
list internally, incrementing it each time. But each iteration, you call 
list.append() to add a new item to the end of the list, so you're continually 
making it longer and preventing the iteration from ending.

Regardless of that, this probably isn't a good use of list comprehensions 
anyway - append() always returns None, so the result of this comprehension 
would be a useless list of Nones. It'd be better to just use a regular for 
loop, or if you're just wanting to copy the list call list.copy() or 
list(your_list).

--
nosy: +Spencer Brown

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45579] [list.append(i) for i in list] causes high resources usage

2021-10-22 Thread TL

New submission from TL :

Version:
Python 3.10.0 - Windows 11 (22000.258) x64
Python 3.9.7 - Windows 11, Manjaro Linux 21.1.5 - Kernel 5.13.13-1-MANJARO x64
CPU: 8 × Intel® Core™ i5-8300H CPU @ 2.30GHz

Steps to reproduce:
1. Create any list, for example your_list = [1, 2, 3]
2. Execute [your_list.append(i) for i in your_list]

--
components: Interpreter Core
messages: 404813
nosy: txlbr
priority: normal
severity: normal
status: open
title: [list.append(i) for i in list] causes high resources usage
type: resource usage
versions: Python 3.10, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com