Popular recipes by Will http://code.activestate.com/recipes/users/4166209/2008-08-06T15:16:54-07:00ActiveState Code RecipesClean preceeding and trailing whitespace in complex list dictionary tuple structures (Python) 2008-08-06T15:16:54-07:00Willhttp://code.activestate.com/recipes/users/4166209/http://code.activestate.com/recipes/576409-clean-preceeding-and-trailing-whitespace-in-comple/ <p style="color: grey"> Python recipe 576409 by <a href="/recipes/users/4166209/">Will</a> (<a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/tuple/">tuple</a>, <a href="/recipes/tags/whitespace/">whitespace</a>). Revision 2. </p> <p>Function to clean trailing and or preceeding whitespace from string types in complex list, dictionary, and tuple structures. This is a recursive function to allow for complete coverage of all items in the structure. Wanted to share it as I needed it and after searching for a while I gave up and wrote one.</p> <p>For example a = ["\rText \r\n", "This one is fine", ["stuff ", [" Something Else"], 4, "Another ", "one", " with"], "\twhitespace\r\n"]</p> <p>print cleanWhiteSpace(a) Result: ["Text", "This one is fine", ["stuff", ["Something Else"], 4, "Another", "one", "with"], "whitespace"]</p>