firstval
1/3/2015 - 11:28 AM

NonDeterminsticSet

import random

random.seed(0)

def MakeData():
    Data = ["Spam"] * 5
    Data.extend(["Eggs"] * 2)
    Data.extend(["Ham"] * 2)
    return Data
    
def NonDeterministic(Data):
    justSpam = set(Data) & set(["Spam"])
    IloveHam = set(Data) & set(["Ham"])
    TastyEgg = set(Data) & set(["Eggs"])

    Breakfast = justSpam | IloveHam | TastyEgg
    DeliciousFactor = random.random()
    return Breakfast, DeliciousFactor

def Deterministic(Data):
    justSpam = [food for food in Data if food == "Spam"]
    IloveHam = [food for food in Data if food == "Ham"]
    TastyEgg = [food for food in Data if food == "Eggs"]

    Breakfast = []
    Breakfast.extend([justSpam[0], IloveHam[0], TastyEgg[0]])
    DeliciousFactor = random.random()
    return Breakfast, DeliciousFactor

menu = MakeData()
print (NonDeterministic(menu))
print (Deterministic(menu))