⇤ ← Revision 1 as of 2008-02-23 21:52:41
Size: 539
Comment:
|
Size: 735
Comment: Solution to problem 8
|
Deletions are marked like this. | Additions are marked like this. |
Line 19: | Line 19: |
= Problem 8: Eliminate consecutive duplicates of list elements = {{{ from itertools import groupby def compress(alist): return [key for key, group in groupby(alist)] }}} |
Python Solutions to [https://prof.ti.bfh.ch/hew1/informatik3/prolog/p-99/ 99 Prolog Prolems].
Index TableOfContents(2)
Problems 1-6
André Roberge has a zip file with solutions to the first six problems, in Crunchy format: [http://crunchy.googlecode.com/files/first_6_of_99_problems.zip First six]
Problem 7: Flatten a nested list structure
Based on the standard library documentation:
from itertools import chain def flatten(listOfLists): return list(chain(*listOfLists))
Problem 8: Eliminate consecutive duplicates of list elements
from itertools import groupby def compress(alist): return [key for key, group in groupby(alist)]