Session 5 Homework 

Session 5 homework. It looks like this will supersede a pull request for Session 4 homework as well.

Chris, thanks for all the commentary. As you can see, I AM paying 
attention and learning! Everytime, you've said "pythonic," so far, I 
have picked something up.

--Dave


On Nov 3 2014 4:11 PM, Christopher H.Barker, PhD wrote:
> In Students/Dave Fugelso/Session 5/dict_and_set_comprehensions.py:
>
>> + print food_prefs
>> +
>> +
>> + #5. Create sets s2, s3 and s4 that contain numbers from zero 
>> through twenty, divisible 2, 3 and 4.
>> +
>> + #Do this with one set comprehension for each set.
>> + #What if you had a lot more than 3? - Dont Repeat Yourself (DRY)
>> + #create a sequence that holds all three sets
>> + #loop through that sequence to build the sets up - so no repeated 
>> code.
>> + #Extra credit: do it all as a one-liner by nesting a set 
>> comprehension inside a list comprehension. (OK, that may be getting 
>> carried away!)
>> + s2 = {n for n in range(0, 21) if n % 2 == 0}
>> + s3 = {n for n in range(0, 21) if n % 3 == 0}
>> + s4 = {n for n in range(0, 21) if n % 2 == 0}
>> + print s2, s3, s4
>> + # or
>> + print [ {n for n in range(0, 21) if n%m == 0} for m in range(2, 
>> 5)]
>
> nice!
>
> --
> Reply to this email directly or view it on GitHub [1].
>
> Links:
> ------
> [1] 
> https://github.com/UWPCE-PythonCert/IntroToPython/pull/67/files#r19774821