質問

I've got 4 lists, which are lists on their selves since they contain 3D point coordinates.

Example

var1 = [[0.09476800262928009, -0.23948000371456146, 0.22791500389575958], 
        [0.015838999301195145, 0.2482910007238388, 0.16062000393867493]]

I need to pick a random list one out of these 4, without making this a list on itself.

I currently doing this with this simple line:

randomVar = random.sample([var1, var2, var3, var4], 1)

Which gives me this result:

[[[0.09476800262928009, -0.23948000371456146, 0.22791500389575958], 
  [0.015838999301195145, 0.2482910007238388, 0.16062000393867493]]]

But I need this:

[[0.09476800262928009, -0.23948000371456146, 0.22791500389575958],
 [0.015838999301195145, 0.2482910007238388, 0.16062000393867493]]

The reckon the answer to this will be pretty easy, but I failed to find a solution for this so far. Still pretty new to scripting so forgive me if I overlooked an obvious solution.

役に立ちましたか?

解決

randomVar = random.choice([var1,var2,var3,var4])

This will produce the result you want.

Example output:

>>> print randomVar

[[0.09476800262928009, -0.23948000371456146, 0.22791500389575958], 
 [0.015838999301195145, 0.2482910007238388, 0.16062000393867493]]

他のヒント

 randomVar = random.sample([var1, var2, var3, var4], 1)[0]
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top