Last active
April 13, 2018 14:41
-
-
Save nainav/f9b2fa3129116a57888766394d0bcedd to your computer and use it in GitHub Desktop.
Programs python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"naina":"naani" | |
print "Find anagram !\n" | |
def anagram(): | |
str1='naina' | |
str2='naina' | |
list1=list(str1) | |
list2=list(str2) | |
list1.sort() | |
list2.sort() | |
print list1,list2 | |
position=0 | |
matches=True | |
if len(list1)==len(list2): | |
while position < len(list1) and matches: | |
if list1[position] == list2[position]: | |
position =position +1 | |
else: | |
matches =False | |
return matches | |
return "length is equal " | |
else: | |
return "not equal" | |
print anagram() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hello World program in Python | |
print "Find minimum Number!\n" | |
def find_min(): | |
list=[3,5,1,4,5,5,1] | |
min=list[0] | |
for a in list: | |
if a < min: | |
min =a | |
return a; | |
res=find_min() | |
print res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 3 code to find Maximum difference | |
# between two elements such that larger | |
# element appears after the smaller number | |
# The function assumes that there are at | |
# least two elements in array. The function | |
# returns a negative value if the array is | |
# sorted in decreasing order. Returns 0 | |
# if elements are equal | |
def maxDiff(arr, arr_size): | |
max_diff = arr[1] - arr[0] | |
for i in range( 0, arr_size ): | |
for j in range( i+1, arr_size ): | |
if(arr[j] - arr[i] > max_diff): | |
max_diff = arr[j] - arr[i] | |
return max_diff | |
# Driver program to test above function | |
arr = [1, 2, 90, 10, 110] | |
size = len(arr) | |
print ("Maximum difference is", maxDiff(arr, size)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment