From a41fe31322e92f84ecee4f3e6295bed2ec9120fd Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Mon, 6 Jan 2014 17:17:02 +0000 Subject: Added dict iterator. --- tests/basics/tests/dict_iterator.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/basics/tests/dict_iterator.py (limited to 'tests') diff --git a/tests/basics/tests/dict_iterator.py b/tests/basics/tests/dict_iterator.py new file mode 100644 index 000000000..f190e32ff --- /dev/null +++ b/tests/basics/tests/dict_iterator.py @@ -0,0 +1,3 @@ +d = {1: 2, 3: 4} +for i in d: + print(i, d[i]) -- cgit v1.2.3 From 4ce6ceadcad294a62f6fb2b23da262dc5cad0793 Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Mon, 6 Jan 2014 17:38:47 +0000 Subject: Added dict.clear. Added 0 to the list of primes. Funky primes, these. --- tests/basics/tests/dict_clear.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tests/basics/tests/dict_clear.py (limited to 'tests') diff --git a/tests/basics/tests/dict_clear.py b/tests/basics/tests/dict_clear.py new file mode 100644 index 000000000..6be2778be --- /dev/null +++ b/tests/basics/tests/dict_clear.py @@ -0,0 +1,6 @@ +d = {1: 2, 3: 4} +print(d) +d.clear() +print(d) +d[2] = 42 +print(d) -- cgit v1.2.3 From d90b19eca56a361d432ab6af9c2305bb3f708e1c Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Mon, 6 Jan 2014 18:11:20 +0000 Subject: Added dict.copy --- tests/basics/tests/dict_copy.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tests/basics/tests/dict_copy.py (limited to 'tests') diff --git a/tests/basics/tests/dict_copy.py b/tests/basics/tests/dict_copy.py new file mode 100644 index 000000000..c3eb7ffc1 --- /dev/null +++ b/tests/basics/tests/dict_copy.py @@ -0,0 +1,5 @@ +a = {i: 2*i for i in range(1000)} +b = a.copy() +for i in range(1000): + print(i, b[i]) +print(len(b)) -- cgit v1.2.3 From cd0887352d18467ea96728e75255ea36f425450d Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Mon, 6 Jan 2014 18:53:16 +0000 Subject: Added dict.get. --- tests/basics/tests/dict_get.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/basics/tests/dict_get.py (limited to 'tests') diff --git a/tests/basics/tests/dict_get.py b/tests/basics/tests/dict_get.py new file mode 100644 index 000000000..fb43a45ea --- /dev/null +++ b/tests/basics/tests/dict_get.py @@ -0,0 +1,3 @@ +for d in {}, {42:2}: + print(d.get(42)) + print(d.get(42,2)) -- cgit v1.2.3 From 0fcbaa442f538c8ffca8a7387f7dc6d280172a5c Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Mon, 6 Jan 2014 19:48:34 +0000 Subject: implemented dict.pop --- tests/basics/tests/dict_pop.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/basics/tests/dict_pop.py (limited to 'tests') diff --git a/tests/basics/tests/dict_pop.py b/tests/basics/tests/dict_pop.py new file mode 100644 index 000000000..602560ce9 --- /dev/null +++ b/tests/basics/tests/dict_pop.py @@ -0,0 +1,12 @@ +d = {1: 2, 3: 4} +print(d.pop(3), d) +print(d) +print(d.pop(1, 42), d) +print(d.pop(1, 42), d) +print(d.pop(1, None), d) +try: + print(d.pop(1), "!!!",) +except KeyError: + print("Raised KeyError") +else: + print("Did not rise KeyError!") -- cgit v1.2.3 From f77dce8a5dda13c759faeabb892d5f439dc05fd5 Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Mon, 6 Jan 2014 20:08:52 +0000 Subject: Added dict.popitem --- tests/basics/tests/dict_popitem.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/basics/tests/dict_popitem.py (limited to 'tests') diff --git a/tests/basics/tests/dict_popitem.py b/tests/basics/tests/dict_popitem.py new file mode 100644 index 000000000..184735cde --- /dev/null +++ b/tests/basics/tests/dict_popitem.py @@ -0,0 +1,11 @@ +d={1:2,3:4} +print(d.popitem()) +print(d) +print(d.popitem()) +print(d) +try: + print(d.popitem(), "!!!",) +except KeyError: + print("Raised KeyError") +else: + print("Did not raise KeyError") -- cgit v1.2.3 From be8fe5be2eb89cd8db741b16dcb50bf5966c33ae Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Mon, 6 Jan 2014 20:25:51 +0000 Subject: Added dict.setdefault --- tests/basics/tests/dict_setdefault.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/basics/tests/dict_setdefault.py (limited to 'tests') diff --git a/tests/basics/tests/dict_setdefault.py b/tests/basics/tests/dict_setdefault.py new file mode 100644 index 000000000..57d0ba451 --- /dev/null +++ b/tests/basics/tests/dict_setdefault.py @@ -0,0 +1,13 @@ +d = {} +print(d.setdefault(1)) +print(d.setdefault(1)) +print(d.setdefault(5, 42)) +print(d.setdefault(5, 1)) +print(d[1]) +print(d[5]) +d.pop(5) +print(d.setdefault(5, 1)) +print(d[1]) +print(d[5]) + + -- cgit v1.2.3 From 27d4ca7693c276d09a911c00c3442729c516dc23 Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Tue, 7 Jan 2014 22:51:51 +0000 Subject: forgot to add test for dict.update --- tests/basics/tests/dict_update.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/basics/tests/dict_update.py (limited to 'tests') diff --git a/tests/basics/tests/dict_update.py b/tests/basics/tests/dict_update.py new file mode 100644 index 000000000..e7ae0bd96 --- /dev/null +++ b/tests/basics/tests/dict_update.py @@ -0,0 +1,10 @@ +d = {1:2, 3:4} +print(d) +d.update(["ab"]) +print(d[1]) +print(d[3]) +print(d["a"]) +print(len(d)) +d.update([(1,4)]) +print(d[1]) +print(len(d)) -- cgit v1.2.3 From 9c83ec0edac2394431a5d1aecba1d666ffdea0a3 Mon Sep 17 00:00:00 2001 From: John R. Lenton Date: Tue, 7 Jan 2014 23:06:46 +0000 Subject: Merge remote-tracking branch 'upstream/master' into dict_feats --- tests/basics/tests/list_sort.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/basics/tests/list_sort.py (limited to 'tests') diff --git a/tests/basics/tests/list_sort.py b/tests/basics/tests/list_sort.py new file mode 100644 index 000000000..eff12b9c8 --- /dev/null +++ b/tests/basics/tests/list_sort.py @@ -0,0 +1,13 @@ +l = [1, 3, 2, 5] +print(l) +l.sort() +print(l) +l.sort(key=lambda x: -x) +print(l) +l.sort(key=lambda x: -x, reverse=True) +print(l) +l.sort(reverse=True) +print(l) +l.sort(reverse=False) +print(l) + -- cgit v1.2.3