<jupyter_start><jupyter_text>Exercise 1Add the specified code for each code cell, running the cells _in order_. Create a variable **`deck`** that represents a deck of [playing cards](https://en.wikipedia.org/wiki/Playing_card). This variable should be a _list_ of 52 elements, each of which is a dictionary with the following keys:- `suit`, with a string value that is either `'hearts'`, `'diamonds'`, `'clubs'`, or `'spades'`.- `rank`, with an interger value ranging from 2 to 14 inclusive (11-14 represent a Jack, Queen, King, or Ace respectively)._Tip:_ use a pair of nested loops to add each combination of suit and rank to the `deck` list!<jupyter_code>##First create empty list
deck = []
##Could create an intermediate suits var, but don't have to
#suits = ['hearts', 'diamonds', 'clubs', 'spades']
for suit in ['hearts', 'diamonds', 'clubs', 'spades']: 
    #I could write this out, or could use a loop to create
    #how?...Range! But 14 is not inclusive, so +1
    for rank in range(2, 14+1): 
        card = {'suit': suit, 'rank': rank} ##This is totally optional. Could just move this down to append!
        ##test it out!
        #print(card)
        ##Am I done? No, need to "put them in the list"
        ##How do I do that? append
        deck.append(card)
deck

##Good example to follow for HW 4<jupyter_output><empty_output><jupyter_text>Create a list **hand** that represents a hand of [Poker](https://en.wikipedia.org/wiki/Poker) (5-card draw). Add 5 cards from the `deck` to this list.- You can add 5 specific cards for testing (check their indices!), or use the `random.shuffle()` function to shuffle the deck and then _slice_ 5 cards from the top.Print out the `hand` so you know what you are dealing with!<jupyter_code>import random
random.shuffle(deck) #Shuffle! runs in place, no need for variable
#deck ##Test: PASS

##Grab first 5 cards = first 5 elements from list 
##Means first five dictionaries
hand = deck[0:5]
hand

#############################
##STOP HERE
##Go back to slides and talk about searching<jupyter_output><empty_output><jupyter_text>Define a function **`contains_queen_of_hearts()`** that takes in a list of cards (e.g., a hand) and returns whether or not the Queen of Hearts is in that list. _For practice, don't use the `in` operator to check for containment_.<jupyter_code>##Alright, your turn, take 5 min, try to solve

##Simple linear search example
def contains_queen_of_hearts(list_of_cards):
    for card in list_of_cards:
        if card == {'suit': 'hearts', 'rank': 12}:
            return True
        ##here? 
        #return False
    ##Nope, has to be outside the loop
    return False
contains_queen_of_hearts(hand)

#############################
##STOP HERE
##Go back to slides and talk about biggestS<jupyter_output><empty_output><jupyter_text>Define a function **`get_high_card()`** that takes in a list of cards and returns the card (dictionary) of the highest value. The "high card" is the one with the highest rank. Cards of different suits but the same rank are considered to have the same value and either may be returned.- Hint: use a "king-of-the-hill" search!<jupyter_code>##Take 5 minutes and try to complete it yourself
def get_high_card(a_list): 
    ##First, how do I find the rank? 
    #highest_card = a_list[0]['rank']
    #print(highest_card)
    highest_card = a_list[0]
    for card in a_list: 
        if card['rank'] > highest_card['rank']: 
            highest_card = card
        ##here?....No!
        #return highest_card
    return highest_card
    
get_high_card(hand)

################STOP
##Go to the Are All Items Big Slide<jupyter_output><empty_output><jupyter_text>Define a function **`is_flush()`** that takes in a list of cards and returns whether or not the list represents a _flush_&mdash;that is, all of the cards have the same _suit_.<jupyter_code>##One way:
# def is_flush(a_list): 
#     same_suit = True
#     prev_card = a_list[0]
#     for card in a_list: 
#         if not card['suit'] == prev_card['suit']: 
#             same_suit = False
#             break
#         else: 
#             prev_card = card
#     return same_suit

##Other way: 
def is_flush(a_list): 
    #First go through loop, then come back here
    target_suit = a_list[0]['suit']
    is_flush = True #Actually, not necessary, can delete
    for card in a_list: 
        
        ##if card['suit'] == ...what...go back and create
        if card['suit'] != target_suit: 
            #is_flush = False #could include, could skip and just return false
            return False
    return True

is_flush(hand)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1180164573408402, 'fraction_numerical': 0.0073624945864010395, 'mean_word_length': 3.6328986960882648, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '435900', 'license': 'MIT', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1384, 'n_words': 577, 'path': 'exercise-1/exercise.ipynb', 'repo_name': 'mportwood/ch10-searching', 'size': '4618'}