0

This is my code,

from array import array
def genId():
    ma={'0':1001,'1':1002,'3':1003,'4':1004,'5':1005,'6':1006,'7':1007}
    print ma
    n=array('i')
    for j in ma:
        n.append(ma[j])
    print n
if __name__=="__main__":
  genId()

I want to sort the values of n. How to do it? and this is the output i'm getting,

{'1': 1002, '0': 1001, '3': 1003, '5': 1005, '4': 1004, '7': 1007, '6': 1006}
array('i', [1002, 1001, 1003, 1005, 1004, 1007, 1006])

please tell me how to sort these array values? thanks in advance..

0

1 Answer 1

1

Sort the values of ma before adding them to the array:

for value in sorted(ma.values()):
    n.append(value)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.