thanks for the excercise just figured out this - <div><br></div><div><div>#!/usr/bin/env python </div><div>import sys </div><div>sys.setrecursionlimit(2000)</div><div> </div><div>def flatten(l): </div>
<div> flattened = [] </div><div> for i in l: </div><div> if type(i) == type([]):</div><div> flattened += flatten(i)</div><div> else: </div><div> flattened.append(i)</div><div> return flattened </div>
<div> </div><div> </div><div>if __name__=='__main__':</div><div> p=[1,[2,3,4],[5,6,],9,[[11,12]]]</div><div> print flatten(p)</div><div><br></div><div>But a google search will lead you to more elegant generic solutions :)</div>
<div><br></div><br><div class="gmail_quote">On Sun, May 9, 2010 at 1:46 PM, gopi krishna <span dir="ltr"><<a href="mailto:dasarathulagopi@gmail.com">dasarathulagopi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi ,<br> Anyone can pls help me in flattening the list.<br>if p is the my list which is defined below<br>p=[1,[2,3,4],[5,6,],9,[[11,12]]]<br>from the above how to get a list <br>as [1,2,3,4,5,6,9,11,12]<br>
<br>--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
<br></blockquote></div><br></div>