tags:

views:

65

answers:

3

Possible Duplicate:
dictionary and stack in python problem

s = [((5, 4), 'South', 1), ((4, 5), 'West', 1)]

I want to put the (5,4) and (4,5) in to the stack.

stack is already implemented in a file...

so I am using :

stack = search.Stack()

Now I can use push and pop for stack.

How to get the (5,4) and (4,5) from the list. I want to make a general form . The elements in s can be more than 2.

A: 
In [173]: s = [((5, 4), 'South', 1), ((4, 5), 'West', 1)]

In [174]: zip(*s)
Out[174]: [((5, 4), (4, 5)), ('South', 'West'), (1, 1)]

In [175]: zip(*s)[0]
Out[175]: ((5, 4), (4, 5))
unutbu
+3  A: 

Pretty simple solution:

for x in s:
    stack.push(x[0])

Unless I'm completely missing something here.

Update

If you want a list of those elements, then try

mylist = [x[0] for x in s]
derekerdmann
+1  A: 
for item in s:
    push(item[0]) //use your implementation of push.
sza