[New-bugs-announce] [issue44930] super-Matlab-style ranged list literal initialization

wang xuancong report at bugs.python.org
Mon Aug 16 23:11:23 EDT 2021


New submission from wang xuancong <xuancong84 at gmail.com>:

Different from Python 2, Python 3 has removed the capability to create a list from a range. In Python 2, we can use range(1,100,2) to create a list [1, 3, 5, ..., 99], but in Python 3, we can only use list(range(1,100,2)) or [*range(1,100,2)] where the latter is even slower. I would like to propose to use something like [1:100:2] to initialize a list, moreover, you can use [1:100:2, 1000:1200:5, 5000:6000, :10] to create a list of multiple segments of ranges, i.e., [1,3,5,...,99,1000,1005,1010,...,1195,5000,5001,5002,...,5999,0,1,2,...,9]. Ranged list creation is quite useful and is often used in multi-thread/multi-processing scheduling or tracked sorting. This is especially useful in deep learning where you want to shuffle the training data but keep track of their corresponding labels. In deep RNN, where every training instance has a different length, after shuffling/sorting, you also need to keep track of their corresponding lengths information and etc. Thanks!

----------
components: Interpreter Core
messages: 399707
nosy: xuancong84
priority: normal
severity: normal
status: open
title: super-Matlab-style ranged list literal initialization
type: enhancement

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44930>
_______________________________________


More information about the New-bugs-announce mailing list