{"id":10278,"date":"2021-10-01T10:00:52","date_gmt":"2021-10-01T04:30:52","guid":{"rendered":"https:\/\/python-programs.com\/?p=10278"},"modified":"2021-11-22T18:33:29","modified_gmt":"2021-11-22T13:03:29","slug":"python-program-to-accept-a-hyphen-separated-sequence-of-words-as-input-and-print-the-words-in-a-hyphen-separated-sequence-after-sorting-them-alphabetically","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-accept-a-hyphen-separated-sequence-of-words-as-input-and-print-the-words-in-a-hyphen-separated-sequence-after-sorting-them-alphabetically\/","title":{"rendered":"Python Program to Accept a Hyphen Separated Sequence of Words as Input and Print the Words in a Hyphen-Separated Sequence after Sorting them Alphabetically"},"content":{"rendered":"

Strings in Python:<\/strong><\/p>\n

“String is a character collection or array”<\/strong><\/p>\n

Well in Python too, for the string data type, we say the same definition. The string is a sequenced character array and is written within single, double, or three quotes. Also, Python does not have the data type character, thus it is used as a string of length 1 if we write ‘s’.<\/p>\n

Given a hyphen-separated sequence of strings, the task is to sort the strings and print them as hyphen-separated strings in Python.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given hyphen-separated string =hello-this-is-btechgeeks<\/pre>\n

Output:<\/strong><\/p>\n

The string before modification =  hello-this-is-btechgeeks\r\nThe string after modification =  btechgeeks-hello-is-this<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given hyphen-separated string =good-morning-codechef<\/pre>\n

Output:<\/strong><\/p>\n

The string before modification = good-morning-codechef\r\nThe string after modification = codechef-good-morning<\/pre>\n

Examples3:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given hyphen-separated string =btechgeeks-online-platform-fror-coding-students<\/pre>\n

Output:<\/strong><\/p>\n

The string before modification = btechgeeks-online-platform-fror-coding-students\r\nThe string after modification = btechgeeks-coding-fror-online-platform-students<\/pre>\n

Program to Accept a Hyphen Separated Sequence of Words as Input and Print the Words in a Hyphen-Separated Sequence after Sorting them Alphabetically in Python<\/h2>\n

Below are the ways to accept a hyphen-separated sequence of strings, the task is to sort the strings and print them as hyphen-separated strings in Python.<\/p>\n