Here's a possible implementation in Python:

def order_list(lst, ordering):
    if ordering == 'Ascending':
        ordered_list = sorted(lst)
    elif ordering == 'Descending':
        ordered_list = sorted(lst, reverse=True)
    else:
        return 'Invalid ordering parameter'

    histogram = ''
    for num in ordered_list:
        histogram += '>' * num + '\n'

    return histogram

You can use this function to order the list and generate the histogram like this:

lst = [2, 6, 8, 4]
ordering = 'Ascending'
histogram = order_list(lst, ordering)
print(histogram)

Output:

>>
>>>>
>>>>>>
>>>>>>>> 

Note that the function returns 'Invalid ordering parameter' if the ordering parameter is not 'Ascending' or 'Descending'. You can modify this behavior according to your specific needs.

Python Function for Ordering Lists and Generating Histograms

原文地址: https://www.cveoy.top/t/topic/pfNK 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录