Compsci 101, Fall 2014, Lab 6

Answer the following questions on the online google form for lab 6.

Part 1: List Comprehensions

Enter your answers in the online form.
  1. print [x**2 for x in range(1,10,2)]
    



  2. print [s[1] for s in ["big", "brown", "bare", "stem", "pea"]]
    



  3. print ['po'*i for i in range(0,5)]
    



  4. print [i*i for i in range(1,10) if i % 2 == 0]
    



  5. print sum([1 for p in [1,2,3,4,5,6,7,8]])
    



  6. print sum([1 for x in "ostentatiously" if "aeiou".find(x) > -1])
    



    Generate List Comprehensions

  7. Using a list comprehension write one expression using the function sum that returns the sum of all the odd integers in a list of integers named nums -- so for [1,3,2,4,5] your expression should evaluate to 9 --- fill in the parentheses: sum(...).




  8. Using a list comprehension and the list functions sum and len write an expression that returns the average length of all the strings in a list of strings named strs. So you'll call two list functions: one with strs as an argument and one with a list comprehension using strs as an argument: combining in one expression sum(...) and len(...). For example, the average length of the strings in the list below is (3+3+4+5)/4 = 15/4 = 3.75
      strs = ["cat", "dog", "bear", "tiger"]
    




Part 2: Transforming Images

  1. Enter your function for GreyScale.





  2. Enter your function for Invert





  3. Enter your function for Darken





  4. Enter your function for Brighten





  5. Enter your function for Solarize