Create a function which takes a list of integers and prints whether the entry is positive, negative or zero.
Modify this function so that instead of printing "positive", "negative" or "zero", it returns the list of corresponding strings. (Can you make this more general? Instead of taking a number to the string "postive", "negative" or "zero", what if I want the squares of the numbers? Or each number incremented by one? How would you allow for this?)
Write a function which takes a list of numbers and returns the sum of the cubes of all the elements.
Write a function which finds the largest item in a list of numbers.
Write a function which returns a list but in reverse order.
Suppose that I'm playing a card game like poker. What are some possible ways I could represent my current hand in the game?
Create a short list of friends' birthdays like we had above. Print a sorted version of this list. Notice the way Python sorts these? Now, write a function which creates a new birthday list but with the order of the name and the birthday swapped. Print out a sorted version of this list. Notice the difference?
Create a list of the numbers 1 to 10. Create a new list which consists of the consecutive pairs of numbers in the list. For example, [(1, 2), (2, 3), (3, 4), ..., (9, 10)]
Write a function which takes two tuples of (x1, y1) and (x2, y2) pairs and returns the "vector sum" (x1+x2, y1+y2). This suggests that we may try to implement an entire collection of support functions for vector algebra. Indeed, this kind of data abstraction is another crucial approach to building programs!
Mon -> 1, Tues -> 2, Wed -> 3, Thur -> 4, ...See if you can use this to build a "reverse" dictionary taking days numbers to day names.
['dog', 'pencil', 'fence', 'dog', 'apple', 'dog', 'dog', 'dog', 'pear', 'pencil', 'pear', 'pear']Using a dictionary, compute the numbers of times each word occurs.
[1, 4, 5, 3, 6, 7, 5, 3, 1, 9, 3, 3, 4, 2]How could you use a set data structure to remove all the duplicates from the list?
users = ['tom', 'pam', 'sasha', 'jj', 'que', 'jeff'] bad = set(['jeff', 'sasha'])It should return an "allowed" list:
['tom', 'pam', 'jj', 'que']