Dup Goto 📝

PythonRecipesListManipulation1

PT2/lang/python/old-notes 10-17 14:11:30
To Pop
17 lines, 78 words, 641 chars Tuesday 2023-10-17 14:11:30

== Chunks This is sometime I keep looking up nice ways for. This in is from [https://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks stackoverflow]. {{c

def chunks(lst, n): """Yield successive n-sized chunks from lst.""" for i in range(0, len(lst), n): yield lst[i:i + n] }} == Get lines of file {{c

as this stands, this removes all \r characters

to convert from windows line endings to unix

removes any trailing blank lines, then splits into lines

def flines(filename): return open(filename).read().replace("\r","").rstrip("\n").split("\n") }}%TIME=1632682084