擅长:python、mysql、java
<pre><code>>>> lis = range(100)
>>> per = .30
>>> no_of_items = int( len(lis) * per) #number of items in 30 percent
>>> lis_b = []
>>> for _ in xrange(no_of_items):
ind = random.randint(0,len(lis)-1) #selects a random index value
lis_b.append(lis.pop(ind)) #pop the item at that index and append to lis_b
...
>>> lis_b
[73, 32, 82, 68, 90, 19, 3, 49, 21, 17, 30, 75, 1, 31, 80, 48, 38, 18, 99, 98, 4, 20, 33, 29, 66, 41, 64, 26, 77, 95]
</code></pre>