This is the place for queries that don't fit in any of the other categories.
Hey guys I'm very new to Python and I'm trying to create a list that automatically populates with zeros or ones based on a preset probability? Any help would be hugely appreciated!
Last edited by Yoriz
on Sun Apr 28, 2013 3:16 pm, edited 1 time in total.
Reason: Changed to a more descriptive title
- Posts: 1
- Joined: Sun Apr 28, 2013 2:28 pm
- Code: Select all
>>> import random
>>> [0 if random.random() < 0.4 else 1 for i in xrange(10)]
[1, 1, 1, 0, 1, 1, 1, 1, 0, 0]
- Posts: 288
- Joined: Mon Mar 04, 2013 7:52 pm
Return to General Coding Help
Who is online
Users browsing this forum: arunkumargupta, W3C [Linkcheck] and 4 guests