a=[2,2,4,1]
b=a
a.sort()// a now points to object[1,2,2,4]
c=sorted(b)//c and b also points to [1,2,2,4]// sort works on array only but sorted also on strings but return array of char
s="sjndk"print(sorted(s))// prints ['d','j','k','n','s']//sorted also works on list of strings(sorts alphabetically)
//for2 strings s1 and s2 to be anagrams
// both conditions should be True//1 their length is same orlen(s1)==len(s2)//2 rearranging chars alphabetically make them equal orsorted(s1)==sorted(s2)
classA:defa(self,st):return1defb(self,s1,s2):
d= self.a(7)return d
obj=A()print(obj.b(1,2))//prints 1// so basically every function in a classhave self which isobject// like in each of them self is there --defa(self,st):&defb(self,s1,s2):// used to other functions of that classand//it's used to call other functions &while calling that other function
// we don't write self inside it
// d= self.a(7)
When applied to numbers, lexicographic order is increasing numerical order, i.e.
increasing numerical order (numbers read left to right).
For example, the permutations of {1,2,3}in lexicographic order are 123,132,213,231,312,and321.
When applied to subsets, two subsets are ordered by their smallest elements.
The [0]* x creates a listwith x elements. So,>>>[0]*5
gives [0,0,0,0,0]******** warn:they all point to the same object.
This is cool for immutables like integers but a pain for things like lists.>>> t =[[]]*5>>> t
[[],[],[],[],[]]>>> t[0].append(5)>>> t
[[5],[5],[5],[5],[5]]>>>
sum(a)
a is the list, it adds up all the numbers in the
list a and takes start to be 0, so returning
only the sum of the numbers in the list.sum(a, start)
this returns the sum of the list+ start
// Python code to demonstrate the working of
//sum()
numbers =[1,2,3,4,5,1,4,5]// start parameter isnot provided
Sum =sum(numbers)print(Sum)// start =10
Sum =sum(numbers,10)print(Sum)