Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 24329

IslandT: Sort list alphabetically with python

$
0
0

You will be given a vector of string(s). You must sort it alphabetically (case-sensitive!!) and then return the first value.

The returned value must be a string and have “***” between each of its letters.

You should not remove or add elements from/to the array.

Above is another problem in codewars, besides asking us to sort the array list and returning the first value in that list, we also need to insert stars within the characters.

def two_sort(array):
    
    array.sort()
    first_string = array[0]
    first_star_string = ''
    limit = len(first_string)

    for i in range(0, limit):
        if i == 0:
            first_star_string += first_string[i]
        else:
            first_star_string +='***'+first_string[i]
            
    return first_star_string

The python solution above is straight forward but needs further improvement if possible, do write down your own answer in the comment box below this post.


Viewing all articles
Browse latest Browse all 24329

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>