Thursday, November 21, 2019

IslandT: Sort list alphabetically with python

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.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...