Link to home
Start Free TrialLog in
Avatar of tech
tech

asked on

How to select items from a list?

There are 10 items in the list l.

list l = [4,8,3,9,2,15,17,19,34,1]


I want to select 70% items (in this case, 7) randomly from the list l, save into another list l1 and the rest left out items which will be 30% (in this case, 3) and save into another list l2.

I can select 70% random items like this but how to select the rest 30%? List l1 and l2 should not have overlapped items.

import random
l1 = random.sample(l, int(.7*len(l)))
l2 = ??

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tech
tech

ASKER

Perfect. Thanks.