# Untitled

Dec 9th, 2021 (edited)
681
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # last lecture / coding workshop, 9.12.2021
2.
3. # some simplified restaurant data
4. r1 = {
5.     "name": "Cheapy Restaurant",
6.     "rating": 3.6
7. }
8.
9. r2 = {
10.     "name": "Expensivo",
11.     "rating": 4.7
12. }
13.
14. r3 = {
15.     "name": "WhatIsThis-Restaurant",
16.     "rating": 1.2
17. }
18.
19. # all restaurants into the list
20. restaurants = [r1, r2, r3]
21.
22. # ask all the questions from user
23. stars = input("How many stars at least (1-5)?\n")
24. stars = int(stars)
25.
26. # then go through all restaurants
27. for company in restaurants:
28.     # assume the restaurant is a matching restaurant in the beginning
29.     good_restaurant = True
30.
31.     # for each question, have a separate if-statement
32.     # and try to flip the boolean into False
33.     if company['rating'] < stars:
34.         # rating didn't match, flip to False
35.         good_restaurant = False
36.
37.     # if none of the previous if-statements flipped the boolean, print the name
38.     if good_restaurant:
39.         print(company['name'])
40.
41.
42. # NEW FILE
43.
44. # filter out all but numbers from string
45.
46. # testing with a string of hours, minutes and seconds
47. test = "10h 33min 25sec"
48.
49. # split into three parts by space character
50. parts = test.split(" ")
51.
52. # go through each piece, in this case ['10h', '33min', '25sec']
53. for t in parts:
54.     # remove all non-numeric characters
55.     # => results in a string
56.     numeric_filter = filter(str.isdigit, t)
57.
58.     # numeric_filter is a list of each number
59.     # => combine them back to one string
60.     numeric_string = "".join(numeric_filter)
61.
62.     # print out numbers only
63.     print(numeric_string)
64.
65.
RAW Paste Data