lists changed to tuples unexpectedly!

Chris Fonnesbeck spam at fisher.forestry.uga.edu
Thu Nov 14 09:44:41 EST 2002


A very strange thing is occurring to me in Python 2.2.2; I have a module
that builds a tuple of nested lists like the following:

# All possible action combinations
actions = [(((i,0),),((j,j),)) for i in (0,1,2,3,4) for j in
(0.0,0.1,0.2)]

I then pass this list as an argument to a class within the module, and it
magically becomes a tuple of tuples:

class QOptimizer(ReinforcementLearning.GradientDescentWatkinsQ):
    'Optimization using Q(Lambda) RL algorithm'

    def __init__(self,
                 actions,
                 states,
                 init_state,
                 state_dynamics_function,
                 objective_function,
                 rounding = 0,
                 roundto = 50000,
                 Alpha = 0.1,
                 Epsilon = 0.2):

	print actions

	... etc.

This gives:

[[[   [ 0.   0. ]]
  [   [ 0.   0. ]]]
 [[   [ 0.   0. ]]
  [   [ 0.1  0.1]]]
 [[   [ 0.   0. ]]
  [   [ 0.2  0.2]]]
 [[   [ 1.   0. ]]
  [   [ 0.   0. ]]]
 [[   [ 1.   0. ]]
  [   [ 0.1  0.1]]]
 [[   [ 1.   0. ]]
  [   [ 0.2  0.2]]]
 [[   [ 2.   0. ]]
  [   [ 0.   0. ]]]
 [[   [ 2.   0. ]]
  [   [ 0.1  0.1]]]
 [[   [ 2.   0. ]]
  [   [ 0.2  0.2]]]
 [[   [ 3.   0. ]]
  [   [ 0.   0. ]]]
 [[   [ 3.   0. ]]
  [   [ 0.1  0.1]]]
 [[   [ 3.   0. ]]
  [   [ 0.2  0.2]]]
 [[   [ 4.   0. ]]
  [   [ 0.   0. ]]]
 [[   [ 4.   0. ]]
  [   [ 0.1  0.1]]]
 [[   [ 4.   0. ]]
  [   [ 0.2  0.2]]]]

Why did I make lists, and get tuples?

TIA,
cjf



More information about the Python-list mailing list