Finding the smallest number lexicographically












1















I'm trying to print smallest number. My prof calls it lexicographical order I think.



For example, I have this list :



[27312,31539]
[49494,26089]
[2946,28149]


The result should be:



27312
26089
28149


Why 28149 is smaller than 2946 so, 2 = 2, but the next int 8<9 ,so it prints 28149.



Is it possible to implement this using lambda ?










share|improve this question

























  • Is lambda compulsory? Because, it does not look like a good use case for lambdas.

    – Austin
    Nov 14 '18 at 17:40













  • As I see it can be solved also without ,thank you :)

    – LordNord
    Nov 14 '18 at 17:54
















1















I'm trying to print smallest number. My prof calls it lexicographical order I think.



For example, I have this list :



[27312,31539]
[49494,26089]
[2946,28149]


The result should be:



27312
26089
28149


Why 28149 is smaller than 2946 so, 2 = 2, but the next int 8<9 ,so it prints 28149.



Is it possible to implement this using lambda ?










share|improve this question

























  • Is lambda compulsory? Because, it does not look like a good use case for lambdas.

    – Austin
    Nov 14 '18 at 17:40













  • As I see it can be solved also without ,thank you :)

    – LordNord
    Nov 14 '18 at 17:54














1












1








1








I'm trying to print smallest number. My prof calls it lexicographical order I think.



For example, I have this list :



[27312,31539]
[49494,26089]
[2946,28149]


The result should be:



27312
26089
28149


Why 28149 is smaller than 2946 so, 2 = 2, but the next int 8<9 ,so it prints 28149.



Is it possible to implement this using lambda ?










share|improve this question
















I'm trying to print smallest number. My prof calls it lexicographical order I think.



For example, I have this list :



[27312,31539]
[49494,26089]
[2946,28149]


The result should be:



27312
26089
28149


Why 28149 is smaller than 2946 so, 2 = 2, but the next int 8<9 ,so it prints 28149.



Is it possible to implement this using lambda ?







python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 17:51









isherwood

37.2k1082111




37.2k1082111










asked Nov 14 '18 at 17:33









LordNordLordNord

707




707













  • Is lambda compulsory? Because, it does not look like a good use case for lambdas.

    – Austin
    Nov 14 '18 at 17:40













  • As I see it can be solved also without ,thank you :)

    – LordNord
    Nov 14 '18 at 17:54



















  • Is lambda compulsory? Because, it does not look like a good use case for lambdas.

    – Austin
    Nov 14 '18 at 17:40













  • As I see it can be solved also without ,thank you :)

    – LordNord
    Nov 14 '18 at 17:54

















Is lambda compulsory? Because, it does not look like a good use case for lambdas.

– Austin
Nov 14 '18 at 17:40







Is lambda compulsory? Because, it does not look like a good use case for lambdas.

– Austin
Nov 14 '18 at 17:40















As I see it can be solved also without ,thank you :)

– LordNord
Nov 14 '18 at 17:54





As I see it can be solved also without ,thank you :)

– LordNord
Nov 14 '18 at 17:54












1 Answer
1






active

oldest

votes


















2














You can use the min function with str as a key function:



print(min([27312,31539], key=str))
print(min([49494,26089], key=str))
print(min([2946,28149], key=str))


This outputs:



27312
26089
28149





share|improve this answer



















  • 1





    Thank you, I didn't even think that it can be solved so easily. It's strange how it works, i mean by key of str

    – LordNord
    Nov 14 '18 at 17:53











  • With lambda - func = lambda array: min(array, key=str)

    – Freund Allein
    Nov 14 '18 at 17:55











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305834%2ffinding-the-smallest-number-lexicographically%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You can use the min function with str as a key function:



print(min([27312,31539], key=str))
print(min([49494,26089], key=str))
print(min([2946,28149], key=str))


This outputs:



27312
26089
28149





share|improve this answer



















  • 1





    Thank you, I didn't even think that it can be solved so easily. It's strange how it works, i mean by key of str

    – LordNord
    Nov 14 '18 at 17:53











  • With lambda - func = lambda array: min(array, key=str)

    – Freund Allein
    Nov 14 '18 at 17:55
















2














You can use the min function with str as a key function:



print(min([27312,31539], key=str))
print(min([49494,26089], key=str))
print(min([2946,28149], key=str))


This outputs:



27312
26089
28149





share|improve this answer



















  • 1





    Thank you, I didn't even think that it can be solved so easily. It's strange how it works, i mean by key of str

    – LordNord
    Nov 14 '18 at 17:53











  • With lambda - func = lambda array: min(array, key=str)

    – Freund Allein
    Nov 14 '18 at 17:55














2












2








2







You can use the min function with str as a key function:



print(min([27312,31539], key=str))
print(min([49494,26089], key=str))
print(min([2946,28149], key=str))


This outputs:



27312
26089
28149





share|improve this answer













You can use the min function with str as a key function:



print(min([27312,31539], key=str))
print(min([49494,26089], key=str))
print(min([2946,28149], key=str))


This outputs:



27312
26089
28149






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 17:47









blhsingblhsing

33.4k41437




33.4k41437








  • 1





    Thank you, I didn't even think that it can be solved so easily. It's strange how it works, i mean by key of str

    – LordNord
    Nov 14 '18 at 17:53











  • With lambda - func = lambda array: min(array, key=str)

    – Freund Allein
    Nov 14 '18 at 17:55














  • 1





    Thank you, I didn't even think that it can be solved so easily. It's strange how it works, i mean by key of str

    – LordNord
    Nov 14 '18 at 17:53











  • With lambda - func = lambda array: min(array, key=str)

    – Freund Allein
    Nov 14 '18 at 17:55








1




1





Thank you, I didn't even think that it can be solved so easily. It's strange how it works, i mean by key of str

– LordNord
Nov 14 '18 at 17:53





Thank you, I didn't even think that it can be solved so easily. It's strange how it works, i mean by key of str

– LordNord
Nov 14 '18 at 17:53













With lambda - func = lambda array: min(array, key=str)

– Freund Allein
Nov 14 '18 at 17:55





With lambda - func = lambda array: min(array, key=str)

– Freund Allein
Nov 14 '18 at 17:55




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305834%2ffinding-the-smallest-number-lexicographically%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine