I use python.I'm having trouble making the following program. [Closed]

Asked 2 years ago, Updated 2 years ago, 32 views

Do you want to improve this question?Edit your post to clarify the issue you are trying to resolve by adding details.

Closed 2 years ago.

Two years ago

The question is, "Define a function that returns a string of hyphenated words and hyphenated words."
Examples of implementation include:
def hyphen_sorted(connectedstring):

print(hyphen_sorted('red-green-blue')


Examples of execution 'blue-green-red'
I would like to make it

python python3

2022-09-29 22:17

3 Answers

Split
Sorted
Join
I think I can manage it if I combine them around


2022-09-29 22:17

Split is used to break down strings.
In this case, we break down the red-green-blue with - and break it apart.
Then sort by Sorted and join together.
In a stack overflow, the answer to the homework itself is
I don't think so well.
Try writing your own program based on the hint and if it doesn't work well
If you ask again, you will be able to answer.


2022-09-29 22:17

It's not very simple, but I wrote it down.
How about this?

def hyphen_sorted(connectedstring):
    string_list = connected string.split('-')
    US>string_list.sort()
    return'-'.join(string_list)

print(hyphen_sorted('red-green-blue'))


2022-09-29 22:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.