Welcome To Snipplr


Everyone's Recent Python Snippets Tagged list



« Prev 1 Next »
This shows how to convert values from a dictionary and make them a list.
0 3321 posted 9 years ago by GabrielTheodoulos
Flatten a list of lists (or tuple of tuples, list of tuples, etc.) to any depth of nesting using no mutable objects.
1 3617 posted 10 years ago by alces
use flatten to reduce a given list to non-list elements. All elements that are no list will be kept and the lists will be expanded...
0 1000 posted 14 years ago by abstraktor
0 1415 posted 14 years ago by magicrebirth
0 1091 posted 14 years ago by silviud
The resulting tree is represented through a dict where each father gets a key (with all the children as args)
0 1322 posted 14 years ago by magicrebirth
Turning a dictionary into a list or an iterator is easy. To get a list of keys, you can just cast the dict into a list. It's cleaner, though to call .keys() on the dictionary to get a list of the keys, or .iterkeys() to get an iterator. Similarly, yo...
0 1009 posted 15 years ago by magicrebirth
This function takes a list of string and sorts them based on their similarity. The percent at which they match can be defined in the second parameter (default 75%).
0 1406 posted 15 years ago by gdvickery
create a dictionary from the data in two lists
0 1253 posted 15 years ago by magicrebirth
// Is there a way in python to convert a list say [1,2,3,4] to a string and // also how to convert a string to a list? // use str() or repr() to convert to a string. // eval() will convert back to a list.
0 1030 posted 15 years ago by magicrebirth
1 1343 posted 15 years ago by magicrebirth
Turns the list [1,2,3] to ['1','2','3']
0 1090 posted 16 years ago by fnurl
I made this ;) Python's operator class is what you need to know if you want to avoid using lambda functions or define your own helper functions in many cases.
1 1259 posted 16 years ago by fnurl
1 1399 posted 18 years ago by whitetiger
« Prev 1 Next »