Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52181

Suggestion: PEP for popping slices from lists

Newsgroups comp.lang.python
Date 2013-08-08 02:45 -0700
Message-ID <dac4873d-4111-4880-9ce5-80f4ecf11685@googlegroups.com> (permalink)
Subject Suggestion: PEP for popping slices from lists
From Neatu Ovidiu Gabriel <neatuovi@gmail.com>

Show all headers | View raw


The list.pop(index) returns the element represented by the index and also reduces the list by removing that element. So it a short one liner for doing both things.
But when it comes for popping a slice of the list there is nothing similar for doing in that simple way.

If you want to remove a slice and also reduce the list you will have something like this:

a_list, a_slice = a_list[:size], a_list[size:]

or even worser if you try to do the same for something in the middle.

My proposal is the extension of list.pop for accepting a way for popping slices.

When doing this:

a_list.pop(i,j)

pop will return the slice [i,j] and remove it from the list.

For popping from an index to the end:

a_list.pop(i, len(a_list))

Or even emptying the whole list:

a_list.pop(0, len(a_list))


So this is it :)

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Suggestion: PEP for popping slices from lists Neatu Ovidiu Gabriel <neatuovi@gmail.com> - 2013-08-08 02:45 -0700
  Re: Suggestion: PEP for popping slices from lists Peter Otten <__peter__@web.de> - 2013-08-08 12:07 +0200
    Re: Suggestion: PEP for popping slices from lists Neatu Ovidiu <neatuovi@gmail.com> - 2013-08-08 03:38 -0700
      Re: Suggestion: PEP for popping slices from lists Nicholas Cole <nicholas.cole@gmail.com> - 2013-08-08 12:12 +0100
        Re: Suggestion: PEP for popping slices from lists Neatu Ovidiu <neatuovi@gmail.com> - 2013-08-08 04:40 -0700
          Re: Suggestion: PEP for popping slices from lists Skip Montanaro <skip@pobox.com> - 2013-08-08 09:20 -0500
        Re: Suggestion: PEP for popping slices from lists Neatu Ovidiu <neatuovi@gmail.com> - 2013-08-08 04:44 -0700
          Re: Suggestion: PEP for popping slices from lists Neatu Ovidiu <neatuovi@gmail.com> - 2013-08-08 04:50 -0700
            Re: Suggestion: PEP for popping slices from lists Nicholas Cole <nicholas.cole@gmail.com> - 2013-08-08 14:08 +0100
              Re: Suggestion: PEP for popping slices from lists Neatu Ovidiu <neatuovi@gmail.com> - 2013-08-08 06:32 -0700
                Re: Suggestion: PEP for popping slices from lists Nicholas Cole <nicholas.cole@gmail.com> - 2013-08-08 15:03 +0100
          Re: Suggestion: PEP for popping slices from lists Terry Reedy <tjreedy@udel.edu> - 2013-08-08 16:03 -0400
          Re: Suggestion: PEP for popping slices from lists Joshua Landau <joshua@landau.ws> - 2013-08-08 22:32 +0100
          Re: Suggestion: PEP for popping slices from lists Tim Chase <python.list@tim.thechases.com> - 2013-08-08 16:50 -0500
          Re: Suggestion: PEP for popping slices from lists Terry Reedy <tjreedy@udel.edu> - 2013-08-08 18:10 -0400

csiph-web