Search
Code Directory
 ASP
 ASP.NET
 C/C++
 CFML
 CGI/PERL
 Delphi
 Development
 Flash
 HTML
 Java
 JavaScript
 Pascal
 PHP
 Python
 SQL
 Tools
 Visual Basic & VB.NET
 XML
New Code
dbForge Studio for PostgreSQL 2.3.212
HTMLPad 2020 16.2
WeBuilder 2020 16.2
Rapid CSS 2020 16.2
Rapid PHP 2020 16.2
C# HTML to PDF 2020.8.1
Flowrigami 1.0.0.1
Vue Injector 3.3
Spectrum Analyzer pro Live 2019
Devart Excel Add-in for HubSpot 2.1
RentALLScript - Airbnb clone 2.2
SuiteCRM Theme Customization 7.11.6
iScripts NetMenus 3.1
iScripts EasyIndex 2.2
iScripts EasySnaps 2.0
Top Code
IcrediBB Bulletin Board System 1.0
T-Shirt Designer Script 1.65
RentALL-Airbnb clone script 1.8.0
Simple Fuzzy Control Demonstration 1.0
Library Management System 1.0
Yet Another Library Management SYStem 1.0
MLM Software ONE 1.5.46
Simple Web Content Management System for Scripts 1.1
Azizi search engine script PHP 4.1.10
ChequePRO Cheque Printing writing System 1.0
Math Solver 1.0.1.37
School College ERP 1.3.2
Metastockread 1.0
Social Media Exchange Script (PES Pro) 2.0
TMetastock 1.00
Top Rated
Uber Clone with Safety Measure Addons 2.0
Answers phpSoftPro 3.12
phpEnter 5.1.
Quick Maps For Dynamics CRM 3.1
Single Leg MLM 1.2.1
Azizi search engine script PHP 4.1.10
Paste phpSoftPro 1.4.1
Extreme Injector 3.7
Deals and Discounts Website Script 1.0.2
Solid File System OS edition 5.1
Classified Ad Lister 1.0
Aglowsoft SQL Query Tools 8.2
Invoice Manager by PHPJabbers 3.0
ICPennyBid Penny Auction Script 4.0
PHP Review Script 1.0
Flattening an arbitrarily deep list (or any iterator) 
File ID: 64032






Flattening an arbitrarily deep list (or any iterator) 
Download Flattening an arbitrarily deep list (or any iterator) http://code.activestate.com/recipes/578092-flattening-an-arbitrarily-deep-list-or-any-iterato/Report Error Link
License: Freeware
Downloads: 9
Submit Rating:
Flattening an arbitrarily deep list (or any iterator)  Description
Description: What if you had a list like this: [1, -10, [1,2,[3,4]], xrange(200)], and you just wanted to go through each element in order (wanted it to return a simple list of [1,-10,1,2,3,4,1,2,3,4...199])

I've seen a couple of attempts to flatten arbitrarily deep lists. Many of them involve recursion, like this one: http://rightfootin.blogspot.com/2006/09/more-on-python-flatten.html

Recursion is generally considered non-pythonic (at least to my knowledge), so I have used one which just involves simple iterators instead. Also, recursion will fail if the list is too deep (so it wouldn't really be arbitrary, would it?).

License: Freeware

Related: flatten, iterator, itertools, List, Python, Tuple

O/S:Windows

Downloads: 9



More Similar Code

dep-trace sorts an input dependancy list or table and prints it, and can do other actions. It's default operation is to act like tsort except that it sorts by pure pkg / make dependancy (tsort sorts by grapical topology: see notes about differences).



list() will convert a tuple to a list, but any elements that are also tuples
will stay as such. This utility function fully converts an arbitrary "tuple tree" to a same-structured list.



This function simply takes a single-dimension sequence and converts into into an HTML unordered list. This function makes it simple to present the contents of a sequence on the web in an neat fashion.



Restricted Access - IP addresses create a system to restrict access to an entire web site or any number of pages in the web site based on a client's IP address or with a user name. This helps you to keep unwanted visitors away.



This is a very simple wrapper of an iterator or iterable, such that the iterator can be iterated streamingly without generating all elements or any at all, but the object can still be iterated from the beginning as many times as wanted. In effect,...



The KNR Author List Widget plugin, by Nitin Reddy Katkam, displays a list of authors, and editors on the blog as an ordered list, unordered list, or a dropdown list. You can use the ordered list to display a list of 'top authors' on the blog.



Utilities are provided to open an ADO connection, list all the tables
found on the connection, and generate field definitions of any of
the tables. An ADO connection string is used to open the connection.
The field definitions are...



Usage: writeexcel(file, varlist)

Writes data to an Excel xml file on any system (NO Excel or ActiveX required!).

Scalars will end up on a sheet called "Scalars" as name (in the first column) and value (in the...



This plugin adds a sidebar-widget to list an artists upcoming shows or top tracks from Last.FM (using the new 2.0 REST API).

This plugin requires PHP 5.

Current features:

* event listing
* top track...



Read in a tab-delimited (or any separator-delimited like CSV) file and store each column in a list that can be referenced from a dictionary. The keys for the dictionary are the headings for the columns (if any). All data is read in as strings.

User Review for Flattening an arbitrarily deep list (or any iterator)
- required fields
     

Please enter text on the image