09-14

Ongoing topics

Upcoming

  • Changing the collecting while you iterate through it (copy instead)
  • Using unittest to write “check-expects”.

Questions

  1. Make a list of ten foods (allFoods). Make your own function someRand(data, N) to randomly select N items from a given list with replacement.

  2. Randomly select 20 items from the list (with replacement) and use that as foodList for the next problems.

  3. Make a list of ordered pairs (food, number of that food in foodList) so that every possible food appears once.

  4. Create a dictionary foodCount with the same information as the previous problem. That is foodCount[food] is the number of that food in foodList.

  5. Create a function randomCap that takes in a string and puts out a string with a random capitalization, one of three cases: lower(), upper() and title().

  6. Use your function to make a new variable foodListCaps by applying randomCap to foodList.

  7. Sort foodListCaps and print it out.

  8. Sort it again, but in a way that ignores the case of the letters. Print that out too.

  9. Write a function del37 that deletes the items in indices 3 through 7 from a given input list. Verify that it works:

     squares20 = [ x*x for x in range(15) ]
     del37(squares20)
     print(squares20)
    
  10. Make a set containing every food in foodList.

  11. Write a function that takes in a string and returns a set of all of the non-vowels in the string. Test it on your name.

Problems

Everyone does the first one. If you want to skip the questions above, do the second one.