"Book to train programming skills to fight in the world" Python code answer example --1.3 URLify

"Book to train programming skills to fight in the world" Python code answer example --1.3 URLify

table of contents

CHAP1. Arrays and strings

  1. Unique string
  2. Count the number of the same characters
  3. URLify
  4. Palindrome permutation
  5. One-shot conversion
  6. String compression
  7. Rotating Matrix
  8. Matrix of "0"
  9. Rotate string

Python code answer example

def replaceSpaces(str,trueLength):

    spaceCount = 0

    for i in range(trueLength):
        if str[i] == " ":
            spaceCount = spaceCount + 1

    index = trueLength + spaceCount * 2

    target = [0] * index

    for i in range(trueLength-1,-1,-1):

        if str[i] == " ":
            target[index-1] = "0"
            target[index-2] = "2"
            target[index-3] = "%"
            index = index - 3

        else:
            target[index-1] = str[i]
            index = index - 1

    return "".join(target)

input_str = "Mr John Smith"
input_num = len(input_str)

print(replaceSpaces(input_str,input_num))

Recommended Posts

"Book to train programming skills to fight in the world" Python code answer example --1.3 URLify
"Book to train programming skills to fight in the world" Python code answer example --2.6 palindrome
"Book to train programming skills to fight in the world" Python code answer example --2.4 Splitting the list
"Book to train programming skills to fight in the world" Python code answer example --2.7 intersecting nodes
"A book to train programming skills to fight in the world" Python code answer example --1.8 "0" matrix
"A book to train programming skills to fight in the world" Python code answer example --3.1 Three stacks
"Book to train programming skills to fight in the world" Python code answer example --1.4 Permutation of sentences
"A book to train programming skills to fight in the world" Python code answer example --1.9 Rotation of strings
"A book to train programming skills to fight in the world" Python code answer example --1.1 Duplicate character string
"A book to train programming skills to fight in the world" Python code answer example --2.2 Returns the Kth from the back
"A book to train programming skills to fight in the world" Python code Solution example --1.6 String compression
"A book to train programming skills to fight in the world" Python code solution example --1.5 One-shot conversion
"A book to train programming skills to fight in the world" Python code Solution example --1.7 Matrix rotation
"A book to train programming skills to fight in the world" Python code Solution example --2.8 Loop detection
"Book to train programming skills to fight in the world" Python code solution example --- Removed elements between 2.3
"Book to train programming skills to fight in the world" Python code Solution example --2.1 Remove duplicate elements
"A book to train programming skills to fight in the world" Python code answer example --1.2 Count the number of the same characters
"A book to train programming skills to fight in the world" Python code Solution example --2.5 The sum of two numbers shown in the list
Programming to fight in the world ~ 5-1
Programming to fight in the world ~ 5-5,5-6
Programming to fight in the world 5-3
Programming to fight in the world ~ 5-2
Programming to fight in the world-Chapter 4
An example of the answer to the reference question of the study session. In python.
[Kenchon book to Python]-Chapter 3- "Train your problem-solving skills! Algorithms and data structures" I rewrote the posted code to Python!
[Kenchon book to Python]-Chapter 2- "Train your problem-solving skills! Algorithms and data structures" I rewrote the posted code to Python!
[Kenchon book to Python]-Chapter 4-"Train your problem-solving skills! Algorithms and data structures" I rewrote the posted code to Python!
Try to solve the programming challenge book with python3
In the python command python points to python3.8
I wrote the code to write the code of Brainf * ck in python
Sample code to get the Twitter API oauth_token and oauth_token_secret in Python 2.7
What kind of book is the best-selling "Python Crash Course" in the world?
Tips for Python beginners to use the Scikit-image example for themselves 6 Improve Python code
Get the EDINET code list in Python
How to display Hello world in python
Part 1 I wrote an example of the answer to the reference problem of how to write offline in real time in Python
I stumbled on the character code when converting CSV to JSON in Python
I searched for the skills needed to become a web engineer in Python
How to use the C library in Python
Ant book in python: Sec. 2-3, Dynamic Programming (DP)
Personal notes to doc Python code in Sphinx
To dynamically replace the next method in python
Say hello to the world with Python with IntelliJ
Draw graphs in Julia ... Leave the graphs to Python
The trick to write flatten concisely in python
How to get the files in the [Python] folder
I want to display the progress in Python!
Convert cubic mesh code to WKT in Python
Run the output code with tkinter, saying "A, pretending to be B" in python
[Note] How to write QR code and description in the same image with python
I used Python to find out about the role choices of the 51 "Yachts" in the world.
Programming in python
I want to write in Python! (1) Code format check
How to retrieve the nth largest value in Python
I tried to graph the packages installed in Python
How to get the variable name itself in python
Add auto-completion to EV3 Micropyhon programming in VS Code
How to get the number of digits in Python
[Python] Try to read the cool answer to the FizzBuzz problem
How to know the current directory in Python in Blender
Convert the image in .zip to PDF with Python