Advertisement
Luninariel

Homework 2 - Functional Programming Instructions

Sep 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. Purpose
  2.  
  3. To gain skill with the functional programming paradigm and to understand how functional programming is implemented in Python.
  4. Procedure
  5.  
  6. You'll develop a script with a single function definition. Create a new file in IDLE and save it as prg2.py. You may collaborate with up to 2 other students on this lab if you wish, but you must have your collaborators approved by the instructor at least one week before the due date and agree that all students will receive the same grade. You may not share code with any students that are not in your group. Make sure your code is well documented, with a docstrings used at every appropriate opportunity.
  7. What to turn in
  8.  
  9. Once you're finished, turn in the prg2.py file that you created.
  10.  
  11. Instructions
  12.  
  13. Write a generator function called allsubsets which takes a set. This function should generate all subsets of that set. Return each subset as a frozenset. Note that this can be made much easier by using some of the utilities in itertools. However, I'll only give you full credit if you get this working without using itertools.
  14.  
  15. Sample Interactions
  16.  
  17. >>> set(allsubsets({1, 2, 3}))
  18. {frozenset({2}), frozenset({3}), frozenset({1, 2}), frozenset(), frozenset({2, 3}), frozenset({1}), frozenset({1, 3}), frozenset({1, 2, 3})}
  19. >>> set(allsubsets({'a', 'b', 'c', 'd'}))
  20. {frozenset({'d', 'b'}), frozenset({'d', 'c', 'b'}), frozenset({'a'}), frozenset({'c', 'b'}), frozenset({'d', 'a'}), frozenset({'d', 'c'}), frozenset(), frozenset({'c'}), frozenset({'d', 'c', 'b', 'a'}), frozenset({'d', 'b', 'a'}), frozenset({'b'}), frozenset({'b', 'a'}), frozenset({'c', 'b', 'a'}), frozenset({'d', 'c', 'a'}), frozenset({'d'}), frozenset({'c', 'a'})}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement