Close
Close

HackerRank Doubt From Python. Two Solutions Want to Know Which One is Better.

   Aryamann Ningombam

I have two solutions for this and both work. I just want to know which one would workhttps://www.hackerrank.com/challenges/python-sort-sort/problem

 

#!/bin/python3

import math
import os
import random
import re
import sys



if __name__ == '__main__':
    word = input().split()
    listof = []
    for i in range(int(word[0])):
        k = input()
        listof.append(list(k.split()))
    index = int(input())
    lmn = []    
    
    for i in listof:
        lmn.append(i[index])

    
    lmn = sorted(list(map(int,lmn)))
    
    for i in lmn:
        for j in listof:
            if i == int(j[index]):
                lmn[lmn.index(i)] = j

    for i in lmn:
        print(' '.join(i))

 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

lmn = []

    word = input().split()

    for i in range(int(word[0])):

        lmnl = input().split()

        lmn.append(lmnl)

    index = int(input())

    def Set(n):

        return n[index]

    

    for i in lmn:

        z = list(map(int,i))

        lmn[lmn.index(i)] = z

    lmn.sort(key = Set)

    for i in lmn:

        print(' '.join(list(map(str,i))))

 

THANKS!!


Answers

Ask Yours
Post Yours
Write your answer