2#python programming

Words
64
Reading
1 min
Listen
Play
9y

I like to mention about 2 functions in python programming which is very useful.

1 Split

You can split a string with any seperator and put into a list very easily with this function.

>>> x = 'car,bus,bike'
>>>x.split (",")
['car','bus','bike']  // you got list, now you can easily run a 'for' or 'while ' loop to get values

2.map
Map applies a function to all the items in an input_list.

>>>my_list = [1,3 4 5]
>>>def sqrt (a):
>>>      return a*a
>>>my_sqlist = map (sqrt,my_list)
>>>print my_sqlist
[1,9,16,25]

In the above example you are easily getting a square for a list elements in the my_list.

2#python programming | Ecency