This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # first, a compact one-liner but limited to 2D sequences (nested just one level): | |
| # obvious, but | |
| # "nested_list" refers to the nested list you want to flatten, | |
| # "row" refers to each list comprising the nested_list | |
| # "itm" refers to each element comprising each row | |
| def flatten(list2D): | |
| return [itm for row in list2d for itm in row] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| try: | |
| ... | |
| except Exception, e: | |
| print("caught an exception defined in class {0}".format(e.__class__.__module__)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print_fn = function(x) {print(format(x, big.mark=','), quote=F)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DF1 = DF[order(DF$factor_var, -xtfrm(DF$numeric_var)),] | |
| DF1$idx = sequence(rle(as.character(DF1$factor_var))$lengths) | |
| $> # e.g., sort a data frame based on 'price' (numeric variable) | |
| $> # 'grouped by' the levels of 'color' (factor, or discrete variable) | |
| $> data(diamonds, package="ggplot2") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pkg_name = paste("~/path/to/package", system('cd /path/to/package; ls adStats*', intern=T), sep="/") | |
| install.packages(pkg_name, repos=NULL, type="source") | |
NewerOlder