ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: My own accounting python euler problem
by Ozz other posts by this author
Nov 8 2009 4:27AM messages near this date
Re: My own accounting python euler problem | Re: My own accounting python euler problem
Oops,

>  For listing all different subsets of a list (This is what I came up 
>  with. Can it be implemented shorter, btw?):
>  
>  def subsets(L):
>          S = []
>          if (len(L) == 1):
>                  return [L, []]

better to check for the empty set too, thus;

if (len(L) == 0):
                 return [[]]

The order of the sets looks better too;

 > >> subset.subsets([1,2,3])
[[], [1], [2], [2, 1], [3], [3, 1], [3, 2], [3, 2, 1]]

cheers,



-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Vsoler
Ozz
Raymond Hettinger
John Machin
Steven D'Aprano
Steven D'Aprano
John Machin
Mel
Steven D'Aprano
Geremy Condra
Gerry
Mrab
Mrab
Vsoler
Ozz
Dan Bishop
Ozz
Geremy Condra
Geremy Condra
Ozz
Ozz
Robert P. J. Day
Martin P. Hellwig
Robert P. J. Day
Robert P. J. Day
Jack Diederich

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved