Skip to content

Instantly share code, notes, and snippets.

@firstval
Forked from MrValdez/NonDeterminsticSet
Last active August 29, 2015 14:12
Show Gist options
  • Save firstval/fee8fea3bd8fe3eaf72d to your computer and use it in GitHub Desktop.
Save firstval/fee8fea3bd8fe3eaf72d to your computer and use it in GitHub Desktop.
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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment