Created
May 4, 2017 04:48
-
-
Save ehedaoo/bc9ba4dee3da0fc0c83e123ef3029480 to your computer and use it in GitHub Desktop.
Write a Python program to get a list,
sorted in increasing order by the last element
in each tuple from a given list of non-empty tuples.
Sample List : [(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)]
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
# Write a Python program to get a list, | |
# sorted in increasing order by the last element | |
# in each tuple from a given list of non-empty tuples. | |
# Sample List : [(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am a beginner still i tried my best...here is the solution buddy...
a=[(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)]
for j in range (1,len(a)) :
for i in range(len(a)-j) :
if a[i][1]>a[i+1][1] :
temp=a[i]
a[i]=a[i+1]
a[i+1]=temp
for i in range(len(a)) :
print(a[i])