Skip to content

Commit 7dc10c2

Browse files
committed
python 3 for scientists
1 parent 3e022b1 commit 7dc10c2

File tree

3 files changed

+284
-170
lines changed

3 files changed

+284
-170
lines changed

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2+
-- python 3 for scientists:
3+
4+
http://python-3-for-scientists.readthedocs.io/en/latest/
5+
6+
17
-- restructure it all:
28

39
after basic introduction class, have students run through ipython

lectures/01-python/python-functions.ipynb

Lines changed: 114 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,33 +303,141 @@
303303
"print(fnew(3))"
304304
]
305305
},
306+
{
307+
"cell_type": "markdown",
308+
"metadata": {
309+
"collapsed": false
310+
},
311+
"source": [
312+
"## Lambdas"
313+
]
314+
},
315+
{
316+
"cell_type": "markdown",
317+
"metadata": {},
318+
"source": [
319+
"Lambdas are \"disposible\" functions. These are small, nameless functions that are often used as arguments in other functions.\n",
320+
"\n",
321+
"Ex, from the official tutorial:"
322+
]
323+
},
306324
{
307325
"cell_type": "code",
308-
"execution_count": null,
326+
"execution_count": 3,
327+
"metadata": {
328+
"collapsed": true
329+
},
330+
"outputs": [],
331+
"source": [
332+
"pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]\n",
333+
"pairs.sort(key=lambda p: p[1])"
334+
]
335+
},
336+
{
337+
"cell_type": "code",
338+
"execution_count": 4,
309339
"metadata": {
310340
"collapsed": false
311341
},
342+
"outputs": [
343+
{
344+
"data": {
345+
"text/plain": [
346+
"[(4, 'four'), (1, 'one'), (3, 'three'), (2, 'two')]"
347+
]
348+
},
349+
"execution_count": 4,
350+
"metadata": {},
351+
"output_type": "execute_result"
352+
}
353+
],
354+
"source": [
355+
"pairs"
356+
]
357+
},
358+
{
359+
"cell_type": "markdown",
360+
"metadata": {},
361+
"source": [
362+
"Here we use a lambda in a extract from a list (with the filter command)"
363+
]
364+
},
365+
{
366+
"cell_type": "code",
367+
"execution_count": 12,
368+
"metadata": {
369+
"collapsed": false
370+
},
371+
"outputs": [
372+
{
373+
"data": {
374+
"text/plain": [
375+
"[0,\n",
376+
" 36,\n",
377+
" 144,\n",
378+
" 324,\n",
379+
" 576,\n",
380+
" 900,\n",
381+
" 1296,\n",
382+
" 1764,\n",
383+
" 2304,\n",
384+
" 2916,\n",
385+
" 3600,\n",
386+
" 4356,\n",
387+
" 5184,\n",
388+
" 6084,\n",
389+
" 7056,\n",
390+
" 8100,\n",
391+
" 9216]"
392+
]
393+
},
394+
"execution_count": 12,
395+
"metadata": {},
396+
"output_type": "execute_result"
397+
}
398+
],
399+
"source": [
400+
"squares = [x**2 for x in range(100)]\n",
401+
"sq = list(filter(lambda x : x%2 == 0 and x%3 == 0, squares))\n",
402+
"sq\n"
403+
]
404+
},
405+
{
406+
"cell_type": "code",
407+
"execution_count": null,
408+
"metadata": {
409+
"collapsed": true
410+
},
411+
"outputs": [],
412+
"source": []
413+
},
414+
{
415+
"cell_type": "code",
416+
"execution_count": null,
417+
"metadata": {
418+
"collapsed": true
419+
},
312420
"outputs": [],
313421
"source": []
314422
}
315423
],
316424
"metadata": {
317425
"kernelspec": {
318-
"display_name": "Python 2",
426+
"display_name": "Python 3",
319427
"language": "python",
320-
"name": "python2"
428+
"name": "python3"
321429
},
322430
"language_info": {
323431
"codemirror_mode": {
324432
"name": "ipython",
325-
"version": 2
433+
"version": 3
326434
},
327435
"file_extension": ".py",
328436
"mimetype": "text/x-python",
329437
"name": "python",
330438
"nbconvert_exporter": "python",
331-
"pygments_lexer": "ipython2",
332-
"version": "2.7.10"
439+
"pygments_lexer": "ipython3",
440+
"version": "3.4.3"
333441
}
334442
},
335443
"nbformat": 4,

0 commit comments

Comments
 (0)