Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lozsui committed Feb 11, 2021
1 parent 81f1f39 commit b0f0274
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 105 deletions.
104 changes: 1 addition & 103 deletions notebooks/fp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"fmt = '{:10} | {:2d} | {:1.3f} | {:10} | {:10}'\n",
"for person, age, height, (father, mother) in persons:\n",
" print(fmt.format(person, age, height, father, mother))\n",
"\n",
"# ------------- Hint -----------------------\n",
"# For naming columns see namedtuple factory.\n",
"# ------------------------------------------"
Expand Down Expand Up @@ -113,109 +114,6 @@
"name": "#%% Splitting\n"
}
}
},
{
"cell_type": "code",
"execution_count": 59,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Assertions are correct.\n"
]
}
],
"source": [
"s = '0123456789'\n",
"out = 'Assertions are correct.'\n",
"try:\n",
" step = 2\n",
" assert s[::step] == '02468'\n",
" start = 7\n",
" assert s[start::step] == '79'\n",
" step = 3\n",
" assert s[::step] == '0369'\n",
" stop = 7\n",
" assert s[:stop:step] == '036'\n",
" assert s[::10] == '0'\n",
"except AssertionError:\n",
" out = 'One of above assertions raises an error.'\n",
"print(out)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% Slicing\n"
}
}
},
{
"cell_type": "code",
"execution_count": 51,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"One of above assertions raises an error.\n"
]
}
],
"source": [
"s = '0123456789'\n",
"out = 'Assertions are correct.'\n",
"try:\n",
" assert s[::-1] == '9876543210'\n",
" assert s[3::-1] == '3210'\n",
" assert s[::-2] == '97531'\n",
" assert s[3::-2] == '31'\n",
" assert s[::-3] == '852'\n",
" assert s[::10] == '0'\n",
"except AssertionError:\n",
" out = 'One of above assertions raises an error.'\n",
"print(out)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% Slicing in reverse\n"
}
}
},
{
"cell_type": "code",
"execution_count": 67,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Assertions are correct.\n"
]
}
],
"source": [
"row = '01234567890123456789'\n",
"row = 'Samuel Bächler 42'\n",
"first_name = slice(0, 7)\n",
"last_name = slice(7, 18)\n",
"age = slice(18, 20)\n",
"out = 'Assertions are correct.'\n",
"try:\n",
" assert row[first_name] == 'Samuel '\n",
" assert row[last_name] == 'Bächler '\n",
" assert row[age] == '42'\n",
"except AssertionError:\n",
" out = 'One of above assertions raises an error.'\n",
"print(out)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% slice method\n"
}
}
}
],
"metadata": {
Expand Down
47 changes: 45 additions & 2 deletions tests/test_fp.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,48 @@ def test_if_object_is_changeable():
assert b_true == fp.fixed(unchangeable_tuple)


def test_github_communication():
assert 1 == 1
s = '0123456789'


def test_slicing_example():
step = 2
assert s[::step] == '02468'
start = 7
assert s[start::step] == '79'
step = 3
assert s[::step] == '0369'
stop = 7
assert s[:stop:step] == '036'
assert s[::10] == '0'


def test_slicing_in_reverse():
assert s[::-1] == '9876543210'
assert s[3::-1] == '3210'
assert s[::-2] == '97531'
assert s[3::-2] == '31'
assert s[::-3] == '9630'
assert s[::10] == '0'


def test_slice_method_example():
row = '01234567890123456789'
row = 'Samuel Bächler 42'
first_name = slice(0, 7)
last_name = slice(7, 18)
age = slice(18, 20)
assert row[first_name] == 'Samuel '
assert row[last_name] == 'Bächler '
assert row[age] == '42'


"""
In fp.ipynb in the notebooks section there are examples on
- Grabbing Excess Items: a, b, *rest = range(5)
- Grabbing Excess Items: a, *middle, b = range(5)
- Nested Unpacking: person, age, height, (father, mother) in persons
- Splitting: my_list[:2]
"""

0 comments on commit b0f0274

Please sign in to comment.