Sandwich

A sandwich is a food typically consisting of vegetables, sliced cheese or meat, placed on or between slices of bread.
Not a useful library

This is just a place for me to play around with python, jupyter notebook, nbdev, quarto, and pypi.

Let’s make a sandwich.

An egg sandwich (source).

Ingredients

First, we need meat. Let’s say we have ham and turkey.

meat
['ham', 'turkey']

We use index to choose one from the list. For instance, we can use 0 for ham and 1 for turkey.

meat[0]
'ham'
meat[1]
'turkey'

Then, we choose what kind of bread we want. We have white or potato.

bread
['white', 'potato']

Same pattern applies for choosing bread.

bread[1]
'potato'

Lastly, we choose either pepperjack or cheddar cheese.

cheese
['pepprjack', 'cheddar']
cheese[0]
'pepprjack'

Sandwich


source

Sandwich

 Sandwich (meat:int, bread:int, cheese:int)

A sandwich with meat, bread, and cheese.

Type Details
meat int An index into meat
bread int An index into bread
cheese int An index into cheese
# show_doc(Sandwich)
sandwich = Sandwich(meat=1, bread=0, cheese=1)
sandwich
A turkey sandwich with white bread and cheddar cheese.

Comparison operators

We can check equality of sandwiches.

test_eq(Sandwich(meat=1, bread=0, cheese=1), Sandwich(meat=1, bread=0, cheese=1))
test_eq(Sandwich(meat=0, bread=0, cheese=1), Sandwich(meat=0, bread=0, cheese=1))
test_ne(Sandwich(meat=1, bread=1, cheese=0), Sandwich(meat=1, bread=1, cheese=1))
test_ne(Sandwich(meat=1, bread=1, cheese=1), Sandwich(meat=0, bread=0, cheese=0))

Dot dot dot…

display(SVG('<svg height="100" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40"/></svg>'))