Professional Documents
Culture Documents
2nd Week Report
2nd Week Report
>>>
>>> MLB_team['Seattle'] = 'Seahawks'
>>> MLB_team
{'Colorado': 'Rockies', 'Boston': 'Red Sox', 'Minnesota':
'Twins',
'Milwaukee': 'Brewers', 'Seattle': 'Seahawks', 'Kansas
City': 'Royals'}
To delete an entry, use the del statement,
specifying the key to delete:
>>>
>>> del MLB_team['Seattle']
>>> MLB_team
{'Colorado': 'Rockies', 'Boston': 'Red Sox', 'Minnesota':
'Twins',
'Milwaukee': 'Brewers', 'Kansas City': 'Royals'}
there are a couple restrictions that
dictionary keys must abide by.
d.pop(<key>[, <default>])
If <key> is present
in d, d.pop(<key>) removes <key> and returns its
assoc d.popitem()
d.update(<obj>)
Example
fruits =
["apple", "banana", "cherry", "kiwi", "mango"]
newlist = []
for x in fruits:
if "a" in x:
newlist.append(x)
print(newlist)
Example
fruits =
["apple", "banana", "cherry", "kiwi", "mango"]
print(newlist)
Advantages of List Comprehension
More time-efficient and space-efficient
than loops.
Require fewer lines of code.
Transforms iterative statement into a
formula.
list comprehension in Python does the
same task and also makes the program
more simple.
List Comprehensions translate the
traditional iteration approach using for
loop into a simple formula hence making
them easy to use.
The list comprehensions in Python are
more efficient both computationally and in
terms of coding space and time than a for a
loop. Typically, they are written in a single
line of code.
Nested List Comprehensions
Nested List Comprehensions are nothing
but a list comprehension within another list
comprehension which is quite similar to
nested for loops. Below is the program
which implements nested loop.
We got to know about these things in the
list comprehension.
How it is used .
What is the purpose of it.
How it works.
Then we got to learn about the Lambda
function in python .
That how it is used .
What is the purpose of the lamba function
in python.
List Comprehensions and Lambda
Lambda Expressions are nothing but
shorthand representations of Python
functions. Using list comprehensions with
lambda creates an efficient combination.
A lambda function is a small anonymous
function.
A lambda function can take any number of
arguments, but can only have one
expression.
Syntax
lambda arguments : expression.
Example
Add 10 to argument a, and return the
result:
x = lambda a : a + 10
print(x(5))
Example -
Multiply argument a with argument b and
return the result.
x = lambda a, b : a * b
print(x(5, 6)).
Why Use Lambda Functions?
The power of lambda is better shown when
one use them as an anonymous function
inside another function.
Then we got to know and to learn about
the map functions which is used in python.
We got to learn all about the mapping
function that how and why it is used .
What is the work of using it.
What is the syntax of it.
map() function returns a map object(which
is an iterator) of the results after applying
the given function to each item of a given
iterable (list, tuple etc.)
Syntax :
map(fun, iter).
Parameters :
fun : It is a function to which map passes
each element of given iterable. iter : It is a
iterable which is to be mapped.
We, can pass one or more iterable to the
map() function.
We got to know about the map and the
purpose of mapping in python.
We got to learn about the different types of
parameters.
We got to know about the syntax.
We got to learn about purpose of mapping
in python in depth.
These are the learning points which I
acquired from the above activites.
Plan for the next week Project ( Pandas and Data Visualization.)
Any leave taken during the week No
Any other point No such other points as of now .