Issue 32595: Deque with iterable object as one object (original) (raw)

Issue32595

Created on 2018-01-18 19:53 by jonathandaniel, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg310256 - (view) Author: Jonathan (jonathandaniel) Date: 2018-01-18 19:53
Creating a deque with an iterable object creates extra overhead if you want to insert it as one element. e.g: import timeit test1 = ''' str = "x" * 100000 lst = [str] ''' test2 = ''' str = "x" * 100000 ''' print(timeit.timeit(test1, number=100000)) print(timeit.timeit(test2, number=100000)) If I want to add a string to a deque i will have to put it in a list first, this causes 23% slower performance in my case. There should be a deque where this overhead is not needed because in most cases this will be used in performance demanding cases.
msg310257 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-01-18 20:27
Sorry Jonathan, this is the way the python containers work if they take an iterable input. In the case of a str, it is not possible for us to know whether you mean for deque('abc') to go it as three arguments or as one. FWIW, if you don't what to put the single element in a list, the API provides the append() method for adding scalars and extend() method for adding iterables: d = deque() d.append('abc') d.extend('abc') Note that lists behave the same way.
msg310269 - (view) Author: Jonathan (jonathandaniel) Date: 2018-01-19 09:08
Hello, I dont know why but yesterday when i appended it behaved like extend. I should sleep more. 2018-01-18 20:27 GMT+00:00 Raymond Hettinger <report@bugs.python.org>: > > Raymond Hettinger <raymond.hettinger@gmail.com> added the comment: > > Sorry Jonathan, this is the way the python containers work if they take an > iterable input. In the case of a str, it is not possible for us to know > whether you mean for deque('abc') to go it as three arguments or as one. > > FWIW, if you don't what to put the single element in a list, the API > provides the append() method for adding scalars and extend() method for > adding iterables: > > d = deque() > d.append('abc') > d.extend('abc') > > Note that lists behave the same way. > > ---------- > resolution: -> not a bug > stage: -> resolved > status: open -> closed > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue32595> > _______________________________________ >
History
Date User Action Args
2022-04-11 14:58:56 admin set github: 76776
2018-01-19 09:08:45 jonathandaniel set messages: +
2018-01-18 20:27:49 rhettinger set status: open -> closedresolution: not a bugmessages: + stage: resolved
2018-01-18 19:56:45 rhettinger set assignee: rhettingernosy: + rhettinger
2018-01-18 19:53:57 jonathandaniel create