Skip to content

Instantly share code, notes, and snippets.

// lambda in verbose form
(int x, int y) -> {return x + y}
// for single like method body, you can remove { } and return.
// due to smart input type inference for lambda, you also do not need to specify data type.
(x, y) -> x + y
// lambda that takes no input and returns 5
() -> 5
// traditionally we will do the following to sort the list
List<String> names = Arrays.asList("peter", "anna", "mike", "xenia");
Collections.sort(names, new Comparator<String>() {
@Override
public int compare(String a, String b) {
return b.compareTo(a);
}
});
// traditionally we will do the following to sort the list
List<String> names = Arrays.asList("peter", "anna", "mike", "xenia");
for (String name : names) {
System.out.print(name + "; ");
}
// (1) Using lambda expression and functional operations
players.forEach((player) -> System.out.print(player + "; "));
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
import pandas as pd
import numpy as np
iris = load_iris()
print "iris.target = ", iris.target
print "iris.target_name = ", iris.target_names
# populate panda DataFrame where data parameter can take dict, numpy.narray