Skip to content

Instantly share code, notes, and snippets.

@aaronshaver
aaronshaver / append_extend.py
Created May 5, 2022 20:55
Python list.append() vs list.extend()
# append adds its argument as a single element to the end of a list.
# The length of the list itself will increase by one.
# extend iterates over its argument adding each element to the list, extending the list
my_list = [1, 2, 3]
my_list.append([4, 5, 6])
# [1, 2, 3, [4, 5, 6]]
my_list = [1, 2, 3]
my_list.extend(4, 5, 6])
# [1, 2, 3, 4, 5, 6]
@aaronshaver
aaronshaver / Java Hashmap Sort By Value.java
Created May 5, 2022 23:24
Java: print HashMap entries sorted by value
// code:
handRankCounts.entrySet()
.stream()
.sorted(Map.Entry.comparingByValue()) // .comparingByValue() returns a comparator so we don't have to build one
.forEach(System.out::println);
// example output:
Four of a kind=1
Straight=1
Three of a kind=3