Python Forum
Code golfing: splitting a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code golfing: splitting a list
#6
(Jan-12-2017, 09:13 AM)wavic Wrote: There is an example in the Python documentation: https://docs.python.org/3.5/library/iter...ls-recipes

def grouper(iterable, n, fillvalue=None):
    "Collect data into fixed-length chunks or blocks"
    # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx"
    args = [iter(iterable)] * n
    return zip_longest(*args, fillvalue=fillvalue)

Yes, this is Mekire's suggestion...
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Messages In This Thread
Code golfing: splitting a list - by Ofnuts - Jan-11-2017, 10:04 PM
RE: Code golfing: splitting a list - by ichabod801 - Jan-12-2017, 01:26 AM
RE: Code golfing: splitting a list - by Ofnuts - Jan-12-2017, 08:10 AM
RE: Code golfing: splitting a list - by Mekire - Jan-12-2017, 02:41 AM
RE: Code golfing: splitting a list - by wavic - Jan-12-2017, 09:13 AM
RE: Code golfing: splitting a list - by Ofnuts - Jan-12-2017, 11:33 AM
RE: Code golfing: splitting a list - by ichabod801 - Jan-12-2017, 10:50 PM
RE: Code golfing: splitting a list - by wavic - Jan-12-2017, 11:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  "pythonic" way of splitting up my code? liggisten 4 1,862 Dec-30-2023, 08:23 PM
Last Post: Gribouillis
  Splitting code into several files TLammert 4 2,517 Jun-26-2022, 02:33 PM
Last Post: TLammert
  Splitting strings in list of strings jesse68 3 2,594 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  Splitting String into 2d list cclark135 2 3,545 Aug-26-2019, 01:46 PM
Last Post: ThomasL
  splitting numeric list based on condition python_newbie09 7 12,645 May-27-2019, 03:58 PM
Last Post: python_newbie09
  Need help | splitting list into list Vinci141 3 3,391 Mar-13-2019, 09:09 PM
Last Post: Vinci141
  some ideas for intelligent list splitting? wardancer84 4 4,279 Nov-20-2018, 02:47 PM
Last Post: DeaD_EyE
  Splitting a list help johiah 5 5,711 Mar-21-2017, 04:31 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020