Skip to content

Instantly share code, notes, and snippets.

@ehedaoo
Created May 4, 2017 04:48
Show Gist options
  • Save ehedaoo/bc9ba4dee3da0fc0c83e123ef3029480 to your computer and use it in GitHub Desktop.
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)]
# 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)]
@Prakashsharma9211
Copy link

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])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment