Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7831883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:55:46+00:00 2026-06-02T11:55:46+00:00

This is List L : [’25’, ‘2’, ’15’, ‘4’, ’81’, ’43’] This is the

  • 0

This is List L:

['25', '2', '15', '4', '81', '43'] 

This is the output when I use the command sort(L)

['15', '2', '25', '4', '43', '81'] 

This is what I want as output:

['2', '4', '15', '25', '43', '81'] 

Is there a command to sort numbers in a list as %sort n does in commandline?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T11:55:49+00:00Added an answer on June 2, 2026 at 11:55 am

    This is explained in the documentation. You need to define a function to do the comparison between list entries. The function should return 0 if its arguments are equal, 1 if the the first argument is larger than the second, and -1 if the second argument is larger than the first.

    function! MyCompare(i1, i2)
        return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
    endfunction
    

    Then you can call sort() using your new function as the second argument. Hence:

    let list = ['25', '2', '15', '4', '81', '43']
    echo sort( list, 'MyCompare' )
    

    will echo

    [2, 4, 15, 25, 43, 81]
    

    as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We Have this : List<Person> listPerson ; Want to use the Data of listPerson
I often use this list command in Unix (AIX / KSH): ls -Artl It
I want to sort this list: >>> L = ['A', 'B', 'C', ... 'Z',
I have this list: names = ['john','Jonh','james','James','Jardel'] I want loop over the list and
I saw this list of major version numbers for Java in another post: Java
I have this list in python: fileTypesToSearch = ['js','css','htm', 'html'] and I want to
I want to render this list in a single line. List item1 List item2
I have this list of dictionary below. What i want is to search for
How can I sort this list in descending order? timestamps = [ "2010-04-20 10:07:30",
I want to convert this list. All the data stored into .txt file. one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.