[Python] Write a function called “add_spaces” that takes in an argument called “initial_string”. initial_string will always be a non empty string. The function should return the same string but with an added space in between all of the letters. If there are already spaces in the initial_string passed in, you should not add an extra space in between those spaces.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

[Python] Write a function called “add_spaces” that takes in an argument called “initial_string”. initial_string will always be a non empty string. The function should return the same string but with an added space in between all of the letters. If there are already spaces in the initial_string passed in, you should not add an extra space in between those spaces.

**Example Output:**

```
add_spaces("python")                    ⇒   p y t h o n
add_spaces("my string already has spaces")  ⇒  m y s t r i n g a l r e a d y h a s s p a c e s
add_spaces("a     python     string")  ⇒  a     p y t h o n     s t r i n g
```

- The first example demonstrates the function `add_spaces` being applied to the string `"python"`, resulting in the output `"p y t h o n"`, where each character is separated by a space.
- The second example illustrates the function `add_spaces` applied to the string `"my string already has spaces"`, outputting `"m y s t r i n g a l r e a d y h a s s p a c e s"`.
- The third example shows the function `add_spaces` applied to the string `"a     python     string"`, and it produces `a     p y t h o n     s t r i n g"`, preserving the existing spaces between words and adding spaces between each character within the words.
Transcribed Image Text:**Example Output:** ``` add_spaces("python") ⇒ p y t h o n add_spaces("my string already has spaces") ⇒ m y s t r i n g a l r e a d y h a s s p a c e s add_spaces("a python string") ⇒ a p y t h o n s t r i n g ``` - The first example demonstrates the function `add_spaces` being applied to the string `"python"`, resulting in the output `"p y t h o n"`, where each character is separated by a space. - The second example illustrates the function `add_spaces` applied to the string `"my string already has spaces"`, outputting `"m y s t r i n g a l r e a d y h a s s p a c e s"`. - The third example shows the function `add_spaces` applied to the string `"a python string"`, and it produces `a p y t h o n s t r i n g"`, preserving the existing spaces between words and adding spaces between each character within the words.
Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Types of Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education