diff --git a/Functions/lambda_en.py b/Functions/lambda_en.py index e553b4b..4fbfa45 100644 --- a/Functions/lambda_en.py +++ b/Functions/lambda_en.py @@ -1,6 +1,9 @@ #what is the output of this code? -gun = lambda x:x*x +#lamda functions are single line functions, they can also be used without name as anonymous functions + +gun = lambda x:x*x # gun stores the function data = 1 for i in range(1,3): data+=gun(i) print(gun(data)) + diff --git a/Lists/sort.py b/Lists/sort.py new file mode 100644 index 0000000..cd2fc85 --- /dev/null +++ b/Lists/sort.py @@ -0,0 +1,24 @@ +# Here we will show sorting in lists +# Lists have 2 main methods for sorting - sort and sorted +# added by jagritvats +# sort methods sorts the lists while sorted method does not modify the list but returns the sorted lists + +li=[7,3,9,1,0] +print(li) +li.sort() +print(li) # we can see li has become sorted + + +print() + + +li=[2345,678,2134,7687] +print(li) +li2=sorted(li) # the returned value i.e. sorted list is stored in li2 +print(li2) # sorted list +print("\n Original List:") +print(li) # we can see here original list is unchanged + +print('Reverse Sorted:') +li3=sorted(li,reverse=True) # reverse parameter sorts by descending order +print(li3)