# Questions for today
**Please put your questions in the chat!!**
## Completed
* nesting part 2 from practice exam --> try using this: https://www.scaler.com/topics/find-function-in-python/
* Staying on the same page --> check your e-mail (is it the "record added successfully"? I did that after 9:30am. it should be there by now. Also availabel here: http://www.cse.unsw.edu.au/~cs1010/22T2/content/lectures/form-submission-confirmation.zip)
* Upload files from last Thursday <-- Those should be updated now.
* Why the big deal about tabs vs spaces? They look the same. --> Answer: They look the same on *your* computer, but not when they change to someone else's computer.
* Are there likely to be 4 questions in the coding section? Or less? --> Answer: Unlikely. Probably only one or two.
* regarding alternative data structure for qu 4 it was hard to visualise within 3 hours. Like current we are using list of dictionaries? could it be tuple as alternative or set not sure and did not have much practice also on that. --> Answer: To get more practice on this, come up with practice questions for yourself. (You can share on the forum too.)
### Practicing Data Structures Questions
* Example questions:
* Best kind: Directly related to a computer program.
* Less good, but a great start: Any task you do, or someone does, on a daily/weekly/monthly basis.
* A start: Any hobby, activity, anything really.
* Knitting:
* Knitting patterns - collect knitting patterns
* Collect knitting patterns, each pattern includes how hard it is, maybe a list of stitches that are required to be familiar with to complete it, needle size(s), approximate time it takes to complete the project, NTH/SG user logins, liking patterns, recommending patterns, sharing photos of completed projects.
* Stitch tracker
* Enter the pattern you're working on, and tick of the stitches as you complete them.
* Fantasy sport
* Keep track of previous games data.
#### Knitting Patterns Example
**Specification**
Each knitting pattern includes:
* name/description
* category (toy, blanket, clothing...)
* How hard it is: Easy, Medium, Hard
* List of stitches required
* Needle size(s)
* Approximate time to completion
**Approach 1:**
```{python}
patterns = [
{'name':'blue blanket',
'category':'blanket',
'ease':'easy',
'stitches':['Garter Stitch','Stockinette Stitch'],
'needle sizes':[4,5],
'time':'5 hours',
'pattern':[stitch1, stitch2, stitch3 ...]},
{'name':'red blanket',
'category':'blanket',
'ease':'easy',
'stitches':['Garter Stitch','Stockinette Stitch'],
'needle sizes':[4,5],
'time':'5 hours',
'pattern':[stitch1, stitch2, stitch3 ...]},}
]
```
Thinking about use cases - in what situation would we need this?
**Approach 2:**
```{python}
patterns = {
'easy':[
{'name':'blue blanket',
'category':'blanket',
'stitches':['Garter Stitch','Stockinette Stitch'],
'needle sizes':[4,5],
'time':'5 hours',
'pattern':[stitch1, stitch2, stitch3 ...]},
{'name':'red blanket',
'category':'blanket',
'stitches':['Garter Stitch','Stockinette Stitch'],
'needle sizes':[4,5],
'time':'5 hours',
'pattern':[stitch1, stitch2, stitch3 ...]}
],
'medium':[],
'hard':[]
}
```
**Follow up question, using the data structure:**
1. Use case: The user has selected a pattern and stored its (unique) name. Given the name of a pattern, print out the pattern (sequence of stitches).
2. Use case: The user wants to knit something, but doesn't want to have to learn any new stitches. Given a list of stitches (the ones they already know), return a list of the names of all the patterns which require only those stitches.
Code to write:
* Question 1 with Approach 1
* Question 1 with Approach 2
* Question 2 with Approach 1
* Question 2 with Approach 2
Question 2 Approach 2
```{python}
def get_patterns(patterns, known_stitches):
# For each pattern
for ease in patterns:
for pattern in patterns['ease']
# For each stitch in that pattern
for stitch in
# Check it's in the list of known_stitches
# If all the stitches for that pattern were known, add it to our list to return
```
Code demonstrating printing out each part of your data structure (copy straight into vscode and run):
```{python}
def find_patterns(patterns, known_stitches):
for ease in patterns:
print(ease)
for thing in patterns[ease]:
print(f' {thing}')
for stitch in thing['stitches']:
print(f' {stitch}')
if __name__ == "__main__":
patterns = [
{'name':'blue blanket',
'category':'blanket',
'ease':'easy',
'stitches':['Garter Stitch','Stockinette Stitch'],
'needle sizes':[4,5],
'time':'5 hours',
'pattern':['stitch1', 'stitch2', 'stitch3']},
{'name':'red blanket',
'category':'blanket',
'ease':'easy',
'stitches':['Garter Stitch','Stockinette Stitch'],
'needle sizes':[4,5],
'time':'5 hours',
'pattern':['stitch1', 'stitch2', 'stitch3']}
]
#find_patterns(patterns, ['Garter Stitch'])
patterns2 = {
'easy':[
{'name':'blue blanket',
'category':'blanket',
'stitches':['Garter Stitch','Stockinette Stitch'],
'needle sizes':[4,5],
'time':'5 hours',
'pattern':['stitch1', 'stitch2', 'stitch3']},
{'name':'red blanket',
'category':'blanket',
'stitches':['Garter Stitch','Stockinette Stitch'],
'needle sizes':[4,5],
'time':'5 hours',
'pattern':['stitch1', 'stitch2', 'stitch3']}
],
'medium':[],
'hard':[]
}
find_patterns(patterns2, ['Garter Stitch'])
```