{"id":96,"date":"2012-02-25T00:22:00","date_gmt":"2012-02-25T00:22:00","guid":{"rendered":"http:\/\/sdi.thoughtstorms.info\/?p=96"},"modified":"2012-02-25T00:22:00","modified_gmt":"2012-02-25T00:22:00","slug":"permutations-with-python-generators","status":"publish","type":"post","link":"https:\/\/blog.thoughtstorms.info\/?p=96","title":{"rendered":"Permutations with Python Generators"},"content":{"rendered":"<p dir=\"ltr\">Here&#8217;s something neat.<\/p>\n<p>I wanted to experiment creating different permutations of a collection of items. (In fact I&#8217;m working on some code for laying out shapes on a surface.)<br \/>\nPrototyping in Python to get my ideas straight I came up with this neat generator solution.<\/p>\n<pre dir=\"ltr\">def perm(xs) :\n    if xs == [] :\n        yield []\n    for x in xs :\n        ys = [y for y in xs if not y==x]\n        for p in perm(ys) :\n            yield ([x] + p)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s something neat. I wanted to experiment creating different permutations of a collection of items. (In fact I&#8217;m working on some code for laying out shapes on a surface.) Prototyping in Python to get my ideas straight I came up with this neat generator solution. def perm(xs) : if xs == [] : yield [] [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[174,365],"class_list":["post-96","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-generators","tag-python"],"_links":{"self":[{"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts\/96","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=96"}],"version-history":[{"count":0,"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts\/96\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=96"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=96"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}