scientific_comp_projects/CODE/parallel_computing/functional_programming/first_lesson.py

34 lines
1.1 KiB
Python

scientists = [
{'name': 'Ada Lovelace', 'field': 'math', 'born' : '1815', 'nobel': False},
{'name': 'Emmy Noether', 'field': 'math', 'born' : '1882', 'nobel': False}
]
# Mutable data structures !
scientists[0]['name'] = 'Ed Lovelace'
# print(scientists)
# Hence the data is modified !
# We will use a collection.
import collections
Scientist = collections.namedtuple('Scientist', [
'name',
'field',
'born',
'nobel',
])
#print(Scientist)
ada = Scientist(name='Ada Lovelace', field='math', born=1815, nobel=False)
#print(ada.name)
# And now ada is inmutable !
from pprint import pprint
scientists = (
Scientist(name='Ada Lovelace', field='math', born=1815, nobel=False),
Scientist(name='Emmy Noether', field='math', born=1882, nobel=False),
Scientist(name='Marie Curie', field='physics', born=1867, nobel=True),
Scientist(name='Tu Youyou', field='chemistry', born=1930, nobel=True),
Scientist(name='Ada Yonath', field='chemistry', born=1939, nobel=True),
Scientist(name='Vera Rubin', field='astronomy', born=1928, nobel=False),
Scientist(name='Sally Ride', field='physics', born=1951, nobel=True),
)
pprint(scientists)