This file contains 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
// 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 |
This file contains 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
// 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); | |
} | |
}); |
This file contains 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
// 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 + "; ")); | |
This file contains 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
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 |
NewerOlder