why python don't support "extended slice direct assignment" for lists?

Robert William Hanks astroultraman at gmail.com
Fri Jul 2 22:19:31 EDT 2010


to say is "wrong" i think is a bit too much, its just a different type of
usage, this type of sintax is extensively used in numpy arrays (extended
slice came from numerical python), just asking why not extend the sintax to
python list. (not sure if you can use None as in the code i posted in numpy
but numbers are ok). I was just rewriting some numpy code in pure python (no
numpy for python3 yet), personally i think the pure python way is just ugly
and more expensive.

On Fri, Jul 2, 2010 at 10:55 PM, <python-list-request at python.org> wrote:

> Send Python-list mailing list submissions to
>        python-list at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://mail.python.org/mailman/listinfo/python-list
> or, via email, send a message with subject or body 'help' to
>        python-list-request at python.org
>
> You can reach the person managing the list at
>        python-list-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Python-list digest..."
>
> Today's Topics:
>
>   1. Re: Why defaultdict? (Steven D'Aprano)
>   2. Re: why python don't support "extended slice direct
>      assignment" for   lists? (Shashwat Anand)
>   3. Sorting dicts inside dicts (abhijeet thatte)
>   4. Re: The real problem with Python 3 - no business case for
>      conversion        (was "I strongly dislike Python 3") (Shashwat Anand)
>   5. Crash in PyThread_acquire_lock (moerchendiser2k3)
>   6. Re: why python don't support "extended slice direct
>      assignment" for   lists? (MRAB)
>   7. Re: Sorting dicts inside dicts (MRAB)
>   8. Re: tp_richcompare vs tp_compare (Aahz)
>   9. Re: The real problem with Python 3 - no business case for
>      conversion        (was "I strongly dislike Python 3") (Aahz)
>  10. Re: Anyone using GPG or PGP encryption/signatures in your
>      Python apps? (Martin Manns)
>
>
> ---------- Forwarded message ----------
> From: Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au>
> To: python-list at python.org
> Date: 02 Jul 2010 23:59:52 GMT
> Subject: Re: Why defaultdict?
> On Fri, 02 Jul 2010 04:11:49 +0000, Steven D'Aprano wrote:
>
> > I would like to better understand some of the design choices made in
> > collections.defaultdict.
> [...]
>
>
> Thanks to all who replied.
>
>
> --
> Steven
>
>
>
>
>
> ---------- Forwarded message ----------
> From: Shashwat Anand <anand.shashwat at gmail.com>
> To: Robert William Hanks <astroultraman at gmail.com>
> Date: Sat, 3 Jul 2010 05:32:31 +0530
> Subject: Re: why python don't support "extended slice direct assignment"
> for lists?
>
>
> On Sat, Jul 3, 2010 at 4:54 AM, Robert William Hanks <
> astroultraman at gmail.com> wrote:
>
>> why pure python don't support "extended slice direct assignment" for
>> lists?
>>
>> today we have to write like this,
>>
>> >>> aList=[0,1,2,3,4,5,6,7,8,9]
>> >>> aList
>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>> >>> aList[::2]= [None]*len(aList[::2])  #or do the math by hand, what's
>> not always possible
>>
>
> Can you show me a case where it really is cumbersome.
>
>
>> >>> aList
>> [None, 1, None, 3, None, 5, None, 7, None, 9]
>>
>> why not accept syntax like this for extended slice
>>
>> aList[::2] = None
>>
>> when let's say, the left side is a list and the right side is bool, int or
>> float.
>> the laborious [nunber]*len(aList[::2]) seens to me less readable when you
>> want to set lost of items of a list to the same number.
>> Also correct me if i am wrong, calling len() and building a list to this
>> kind of operation seems a waste.
>>
>
> >>> aList[::2]
> [0, 2, 4, 6, 8]
> Which means you are doing [0, 2, 4, 6, 8] = None, which is plain and simple
> - wrong. How will you define the legitimacy of this statement.
> What you are basically doing here is,,
>
> >>> [None]*len(aList[::2])
> [None, None, None, None, None]
> >>> aList[::2]
> [0, 2, 4, 6, 8]
>
> Setting [0, 2, 4, 6, 8] to [None, None, None, None, None], thereby
> operating on two similar data structure (here list)
>
>
>> Just want some feedback.
>>
>
> Just my thoughts.
>
> ~l0nwlf
>
>
>
> ---------- Forwarded message ----------
> From: abhijeet thatte <abhijeet.thatte at gmail.com>
> To: python-list at python.org
> Date: Fri, 2 Jul 2010 17:17:36 -0700
> Subject: Sorting dicts inside dicts
> Hi,
> I have a huge dict structure like below:
> *
> {'module':{'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}
> *
>
> Module dict and reg_dicts contain many elements than shown.
>
> I want to sort this 'module' dictionary as per 'reg_addr' element in every
> 'reg_dict'.
>
> There is no relation between 'reg_dict' suffix and address. So, reg_dict_0
> can contain reg_address = 2000/72 (any number)
> I do not want output in a list format as the actual dict size is huge which
> I want to use based on key value pair.
>
> So, I want output as :
>
> *
> {'module':{'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}
> *
> *
> *
>
> Is it possible to sort the things? What I guess is Python stores dicts in a
> tree like structure but I am forcing it to store the way I want. Is it
> possible  to do something like that.
>
> Thanks,
>
>
>
>
> ---------- Forwarded message ----------
> From: Shashwat Anand <anand.shashwat at gmail.com>
> To: "Steven D'Aprano" <steve at remove-this-cybersource.com.au>
> Date: Sat, 3 Jul 2010 05:52:46 +0530
> Subject: Re: The real problem with Python 3 - no business case for
> conversion (was "I strongly dislike Python 3")
>
>
> On Sat, Jul 3, 2010 at 5:27 AM, Steven D'Aprano <
> steve at remove-this-cybersource.com.au> wrote:
>
>> On Fri, 02 Jul 2010 12:07:33 -0700, John Nagle wrote:
>>
>> > Where's the business case for moving to Python 3?   It's not faster. It
>> > doesn't do anything you can't do in Python 2.6.  There's no "killer app"
>> > for it. End of life for Python 2.x is many years away; most server Linux
>> > distros aren't even shipping with 2.6 yet. How can a business justify
>> > spending money on conversion to Python 3?
>>
>
> The point is python2.7 is the last 2.x version. It will be supported, bugs
> will be fixed but no new feature will be added. Core devs will concentrate
> on python 3.x. You can still use 2.x, no one is stopping you. But assume
> that it is stagnant now. After some time only security related bugs will be
> fixed. So if you want to wait by then, it's all your wish.
>
> ~l0nwlf
>
>
> ---------- Forwarded message ----------
> From: moerchendiser2k3 <googler.1.webmaster at spamgourmet.com>
> To: python-list at python.org
> Date: Fri, 2 Jul 2010 17:56:35 -0700 (PDT)
> Subject: Crash in PyThread_acquire_lock
> Hi all,
>
> I have a serious problem I want to solve. My app, where
> Python is embedded crashs on OSX (10.6 SL). I can reproduce the crash
> sometimes with a script that makes use of Python threads ( module:
> threading).
>
> 'thelock->locked' is for sure still locked, but I can't identify the
> problem.
> Its just waiting, but it gets a 'EXC_BAD_ACCESS'. The line of the
> crash
> in PyThread_acquire_lock is the following one:
>
> while ( thelock->locked ) {
>    status = pthread_cond_wait(&thelock->lock_released, &thelock-
> >mut);  <<<<<<<<<<
>
> >From the view of my code, I can exclude that the GIL was ensured but
> not properly released
> by PyStateGIL_Ensure and PyStateGIL_Release.
>
> Any ideas how to get rid of this crash somehow? Thanks in advance!!
>
> Bye, moerchendiser2k3
>
> #0  0x00007fff86c95316 in __semwait_signal ()
> #1  0x00007fff86c99131 in _pthread_cond_wait ()
> #2  0x000000011c89f8f4 in PyThread_acquire_lock (lock=0x1013803c0,
> waitflag=1) at thread_pthread.h:452
> #3  0x000000011c84a414 in PyEval_RestoreThread (tstate=0x101380200) at
> Python/ceval.c:334
> #4  0x000000011c889725 in PyGILState_Ensure () at Python/pystate.c:592
>
>
>
>
> ---------- Forwarded message ----------
> From: MRAB <python at mrabarnett.plus.com>
> To: python-list at python.org
> Date: Sat, 03 Jul 2010 02:25:14 +0100
> Subject: Re: why python don't support "extended slice direct assignment"
> for lists?
> Robert William Hanks wrote:
>
>> why pure python don't support "extended slice direct assignment" for
>> lists?
>>
>> today we have to write like this,
>>
>>  >>> aList=[0,1,2,3,4,5,6,7,8,9]
>>  >>> aList
>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>  >>> aList[::2]= [None]*len(aList[::2])  #or do the math by hand, what's
>> not always possible
>>  >>> aList
>> [None, 1, None, 3, None, 5, None, 7, None, 9]
>>
>> why not accept syntax like this for extended slice
>>
>> aList[::2] = None
>>
>> when let's say, the left side is a list and the right side is bool, int or
>> float.
>> the laborious [nunber]*len(aList[::2]) seens to me less readable when you
>> want to set lost of items of a list to the same number.
>> Also correct me if i am wrong, calling len() and building a list to this
>> kind of operation seems a waste.
>>
>> Just want some feedback.
>>
>>  When you're assigning to a list slice, why should it duplicate an int
> but not a list? Or in general, duplicate something that's not iterable
> but not something that is iterable? A string is iterable, so what
> should:
>
> >>> a[ : : 2] = "abcde"
>
> do?
>
> It's just simpler and less surprising the way it is.
>
>
>
> ---------- Forwarded message ----------
> From: MRAB <python at mrabarnett.plus.com>
> To: python-list at python.org
> Date: Sat, 03 Jul 2010 02:34:52 +0100
> Subject: Re: Sorting dicts inside dicts
> abhijeet thatte wrote:
>
>> Hi,
>> I have a huge dict structure like below:
>>
>> /*{'module':{'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}*/
>>
>> Module dict and reg_dicts contain many elements than shown.
>> I want to sort this 'module' dictionary as per 'reg_addr' element in every
>> 'reg_dict'.
>> There is no relation between 'reg_dict' suffix and address. So, reg_dict_0
>> can contain reg_address = 2000/72 (any number)
>> I do not want output in a list format as the actual dict size is huge
>> which I want to use based on key value pair.
>>
>> So, I want output as :
>>
>>
>> /*{'module':{'reg_dict_1':{'name':'xyz','reg_addr':'2002'},'reg_dict_0':{'name':'abc','reg_addr':'2004'},'reg_dict_2':{'name':'pqr','reg_addr':'2008'}}*/
>> /*
>> */
>>
>> Is it possible to sort the things? What I guess is Python stores dicts in
>> a tree like structure but I am forcing it to store the way I want. Is it
>> possible  to do something like that.
>>
>>  Python dicts are implemented as hash tables, not trees, for speed, and
> they are unordered.
>
> If the order matters then you should use an ordered dict instead. You
> should be able to find an implementation of one.
>
>
>
> ---------- Forwarded message ----------
> From: aahz at pythoncraft.com (Aahz)
> To: python-list at python.org
> Date: 2 Jul 2010 18:30:33 -0700
> Subject: Re: tp_richcompare vs tp_compare
> In article <
> d52edb82-4de5-496d-8807-b5d15ee66195 at i31g2000yqm.googlegroups.com>,
> moerchendiser2k3  <googler.1.webmaster at spamgourmet.com> wrote:
> >
> >Do I need to implement both? Looks very redundant, isnt it? Or is it
> >just an extension and tp_richcompare is the better choice here? Can
> >anyone please make the light on here? :)
>
> Nobody else responded, so please take this non-expert advice:
>
> tp_compare is the older and now deprecated slot; you want to use
> tp_richcompare if you don't need to support older versions of Python.
> Don't implement both.
> --
> Aahz (aahz at pythoncraft.com)           <*>
> http://www.pythoncraft.com/
>
> "If you don't know what your program is supposed to do, you'd better not
> start writing it."  --Dijkstra
>
>
>
> ---------- Forwarded message ----------
> From: aahz at pythoncraft.com (Aahz)
> To: python-list at python.org
> Date: 2 Jul 2010 18:36:49 -0700
> Subject: Re: The real problem with Python 3 - no business case for
> conversion (was "I strongly dislike Python 3")
> In article <4c2e79d3$0$1663$742ec2ed at news.sonic.net>,
> John Nagle  <nagle at animats.com> wrote:
> >On 7/2/2010 3:00 PM, Aahz wrote:
> >> In article<4C2E38F5.10708 at animats.com>, John Nagle<nagle at animats.com>
>  wrote:
> >>>
> >>>     5.      Get at least two major hosting services to put up Python 3.
> >>
> >> webfaction.com has python3.1
> >
> >    Any user can install Python 3.x, but it's not there by default.
>
> Yes, it is.  I logged into my webfaction shell, typed python3.1, and got
> a standard Python prompt, without doing anything whatsoever to make
> Python 3.1 available.
>
> >    "http://blog.webfaction.com/python-3-0-is-here"
>
> Is there some reason you're using a broken URL format?
>
> >    If that approach catches on, Python 3 deployment will be much easier.
> >But for now, only a few smaller players like WebFaction are using it.
>
> In the hosting space that makes Python available, WebFaction is hardly a
> smaller player.
> --
> Aahz (aahz at pythoncraft.com)           <*>
> http://www.pythoncraft.com/
>
> "If you don't know what your program is supposed to do, you'd better not
> start writing it."  --Dijkstra
>
>
>
> ---------- Forwarded message ----------
> From: Martin Manns <mmanns at gmx.net>
> To: python-list at python.org
> Date: Sat, 3 Jul 2010 03:53:07 +0200
> Subject: Re: Anyone using GPG or PGP encryption/signatures in your Python
> apps?
> On Thu, 01 Jul 2010 14:48:47 -0400
> python at bdurham.com wrote:
>
> > Curious if any of you are using GPG or PGP encryption and/or
> > signatures in your Python apps?
> ...
> > 4. generating signatures for files that you are exchanging/posting for
> > download?
>
> I use pyme to create and check save file signatures.
>
> > 5. what public keyring services are you using?
>
> None
>
> > Any comments on using the subprocess module to wrap the gpg or openssl
> > command line utilities? This seems to be a common technique for
> > encryption and signing solutions and appears to the technique used by
> > python-gnupg (for example).
>
> pyme works great with Linux.
> However, I have never installed it on a Windows system.
>
> Martin
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100702/2476781a/attachment.html>


More information about the Python-list mailing list