random - generate categorical dataset in python -


suppose have list of ten cities :

["paris", "barcelona", "kolkata", "new york"] 

how can simulate n random datasets of 2 attributes each having 2 cities selected above list:

["paris", "barcelona"] ["barcelona", "kolata"] ["new york", "paris"] ["paris", "barcelona"] ["new york", "paris"] 

you can use random.sample this

data = ["paris", "barcelona", "kolkata", "new york"] import random print [random.sample(data, 2) _ in xrange(5)] 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -