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


Groups > comp.lang.python > #105770

Re: Exclude every nth element from list?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Vincent Vande Vyvre <vincent.vande.vyvre@telenet.be>
Newsgroups comp.lang.python
Subject Re: Exclude every nth element from list?
Date Sat, 26 Mar 2016 18:06:10 +0100
Lines 16
Message-ID <mailman.46.1459012002.28225.python-list@python.org> (permalink)
References <94237154-22af-4e64-85ee-9b4cf334fa6f@googlegroups.com>
Reply-To vincent.vandevyvre@oqapy.eu
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de +e0Ypcup7p0RwYV0ZMbLEgjngEugHkXBcPX+7Oop3sbQ==
Return-Path <vincent.vande.vyvre@telenet.be>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; "'c',": 0.16; "'d',": 0.16; "'e',": 0.16; "'o',": 0.16; "'r',": 0.16; 'excludes': 0.16; 'from:name:vincent vande vyvre': 0.16; 'received:195.130': 0.16; 'received:195.130.137': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'received:telenet-ops.be': 0.16; '\xe9crit': 0.16; 'element': 0.18; '>>>': 0.20; 'select': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'subject:list': 0.26; 'received:be': 0.30; 'list': 0.34; 'something': 0.35; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'list.': 0.37; 'subject:from': 0.39; 'to:addr:python.org': 0.40; 'charset:windows-1252': 0.62; 'python-list': 0.66; 'header:Reply- To:1': 0.67; 'reply-to:no real name:2**0': 0.71
User-Agent Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Thunderbird/38.6.0
In-Reply-To <94237154-22af-4e64-85ee-9b4cf334fa6f@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:105770

Show key headers only | View raw


Le 26/03/2016 17:49, beliavsky--- via Python-list a écrit :
> I can use x[::n] to select every nth element of a list. Is there a one-liner to get a list that excludes every nth element?
Something like that:

 >>> l = list("lkodjuyhrtgfedcvfg")
 >>> l
['l', 'k', 'o', 'd', 'j', 'u', 'y', 'h', 'r', 't', 'g', 'f', 'e', 'd', 
'c', 'v', 'f', 'g']
 >>> ll = [c for i, c in enumerate(l) if i % 3]
 >>> ll.insert(0, l[0])
 >>> ll
['l', 'k', 'o', 'j', 'u', 'h', 'r', 'g', 'f', 'd', 'c', 'f', 'g']



Vincent

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


Thread

Exclude every nth element from list? beliavsky@aol.com - 2016-03-26 09:49 -0700
  Re: Exclude every nth element from list? Gary Herron <gherron@digipen.edu> - 2016-03-26 10:01 -0700
    Re: Exclude every nth element from list? beliavsky@aol.com - 2016-03-26 15:08 -0700
      Re: Exclude every nth element from list? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-26 22:57 +0000
  Re: Exclude every nth element from list? Bob Gailer <bgailer@gmail.com> - 2016-03-26 13:03 -0400
  Re: Exclude every nth element from list? Erik <python@lucidity.plus.com> - 2016-03-26 17:06 +0000
  Re: Exclude every nth element from list? Vincent Vande Vyvre <vincent.vande.vyvre@telenet.be> - 2016-03-26 18:06 +0100
  Re: Exclude every nth element from list? Peter Otten <__peter__@web.de> - 2016-03-26 18:06 +0100
  Re: Exclude every nth element from list? Vincent Vande Vyvre <vincent.vande.vyvre@telenet.be> - 2016-03-26 18:12 +0100
  Re: Exclude every nth element from list? BartC <bc@freeuk.com> - 2016-03-26 17:50 +0000
  Re: Exclude every nth element from list? "Sven R. Kunze" <srkunze@mail.de> - 2016-03-29 15:45 +0200

csiph-web