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)
// for 2 strings s1 and s2 to be anagrams
// both conditions should be True
// 1 their length is same or
len(s1)==len(s2)
// 2 rearranging chars alphabetically make them equal or
sorted(s1)==sorted(s2)
class A:
def a(self,st):
return 1
def b(self,s1,s2) :
d= self.a(7)
return d
obj=A()
print(obj.b(1,2))
//prints 1
// so basically every function in a class have self which is object
// like in each of them self is there -- def a(self,st): & def b(self,s1,s2):
// used to other functions of that class and
//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, and 321.
When applied to subsets, two subsets are ordered by their smallest elements.
The [0] * x creates a list with 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 is not provided
Sum = sum(numbers)
print(Sum)
// start = 10
Sum = sum(numbers, 10)
print(Sum)