python - Random Sample with remove from List -


good evening!still new programming bare me. simple question hope!

i have data in list like:

l = [(3,4,5),(1,4,5),(1,2,3),(1,2,3)] 

i need sample randomly size of 2 wanted used:

import random t1 = random.sample(set(l),2) 

now t1 list of randomly pulled values, wanted remove randomly pulled our initial list our initial list. linear loop task i'm trying larger list. run time take ever!

any suggestions on how go this?

t1 = [l.pop(random.randrange(len(l))) _ in xrange(2)] 

doesn't change order of remaining elements in l.


Comments

Popular posts from this blog

java - Cast from Object to List<String>: CastClassException -

How to set a border for android Imageview in Longpress? -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -