(a) Give function to join multiple variables such as name, age, and weight, provided as strings and integers, into a single text string of the format 'NAME_AGE_WGT.txt'
(b) give code to split the above filename into variables of appropriate type (string or integer)
Given the following text string, demonstrate two different methods to find the word 'the'. Use one which finds the first match and uses base Python if you can, and one (from any library) which finds all matches.
text = """A green hunting cap squeezed the top of the fleshy balloon of a head. The green earflaps, full of large ears and uncut hair and the fine bristles that grew in the ears themselves, stuck out on either side like turn signals indicating two directions at once. Full, pursed lips protruded beneath the bushy black moustache and, at their corners, sank into little folds filled with disapproval and potato chip crumbs. In the shadow under the green visor of the cap Ignatius J. Reilly’s supercilious blue and yellow eyes looked down upon the other people waiting under the clock at the D.H. Holmes department store, studying the crowd of people for signs of bad taste in dress. """
text = """A green hunting cap squeezed the top of the fleshy balloon of a head. The green earflaps, full of large ears and uncut hair and the fine bristles that grew in the ears themselves, stuck out on either side like turn signals indicating two directions at once. Full, pursed lips protruded beneath the bushy black moustache and, at their corners, sank into little folds filled with disapproval and potato chip crumbs. In the shadow under the green visor of the cap Ignatius J. Reilly’s supercilious blue and yellow eyes looked down upon the other people waiting under the clock at the D.H. Holmes department store, studying the crowd of people for signs of bad taste in dress. """
In class we used the timeit module (as a so-called "ipython magic" %timeit). Here we'd like to try using the time module, which gives more control over when to start and stop. Use the time.time() function to measure the running time of a fibanocci(n) calculation for n=30 calculation:
(a) using basic recursion implementation (b) using dynamic programming (see class notes) (c) using memoization via the @lru_cache() decorator (see class notes)
Hint: to use time.time(), save the time as a variable before and after the function calls and take the difference. Note that this time is measured in seconds so the result may be less than a second.
(d) now try increasing n. How high can you go?