"Book to train programming skills to fight in the world" Python code answer example --1.4 Permutation of sentences

"Book to train programming skills to fight in the world" Python code answer example --1.4 Permutation of sentences

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. Rotate matrix
  8. Matrix of "0"
  9. Rotate string

Python code answer example

def isPermutationOfPalindrome(phrase):

    phrase = phrase.lower()
    table = buildCharFrequencyTable(phrase)
    return checkMaxOneOdd(table)

def checkMaxOneOdd(table):
    
    foundOdd = False

    for count in range(len(table)):
        if table[count]%2 == 1:
            if foundOdd:
                return False
            foundOdd = True

    return True 

def getCharNumber(c):

    a = ord("a")
    z = ord("z")
    val = ord(c)

    if a <= val and val <= z:
        return val - a
    
    return -1

def buildCharFrequencyTable(phrase):
    
    table = [0] * 26

    for id in range(len(phrase)):
        c = phrase[id]
        x = getCharNumber(c)

        if x != -1 :
            table[x] = table[x] + 1
    
    return table

print(isPermutationOfPalindrome("Tact Coa"))

Recommended Posts

"Book to train programming skills to fight in the world" Python code answer example --1.4 Permutation of sentences
"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
"A book to train programming skills to fight in the world" Python code answer example --1.9 Rotation of strings
"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
"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 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.5 One-shot conversion
"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 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
An example of the answer to the reference question of the study session. In python.
[Kenchon book to Python] "Train your problem-solving skills! Algorithms and data structures" I tried to rewrite the posted code in Python! -table of contents-
Programming to fight in the world-Chapter 4
[Python] PCA scratch in the example of "Introduction to multivariate analysis"
I wrote the code to write the code of Brainf * ck in python
What kind of book is the best-selling "Python Crash Course" in the world?
[Kenchon book to Python]-Chapter 3- "Train your problem-solving skills! Algorithms and data structures" I rewrote the posted code to Python!
Part 1 I wrote an example of the answer to the reference problem of how to write offline in real time in 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!
How to get the number of digits in Python
Reproduce the execution example of Chapter 4 of Hajipata in Python
I used Python to find out about the role choices of the 51 "Yachts" in the world.
Implemented the algorithm of "Algorithm Picture Book" in Python3 (Heapsort)
Reproduce the execution example of Chapter 5 of Hajipata in Python
To do the equivalent of Ruby's ObjectSpace._id2ref in Python
[Python] Programming to find the number of a in a character string that repeats a specified number of times.
Implemented the algorithm of "Algorithm Picture Book" in Python3 (Bubble Sort)
Implemented the algorithm of "Algorithm Picture Book" in Python3 (selection sort)
Part 1 I wrote the answer to the reference problem of how to write offline in real time in Python
How to determine the existence of a selenium element in Python
How to implement Java code in the background of RedHat (LinuxONE)
How to know the internal structure of an object in Python
[Cloudian # 9] Try to display the metadata of the object in Python (boto3)
How to check the memory size of a variable in Python
First python ② Try to write code while examining the features of python
Output the contents of ~ .xlsx in the folder to HTML with Python
Feel free to change the label of the legend in Seaborn in python
How to check the memory size of a dictionary in Python
Visualize the frequency of word occurrences in sentences with Word Cloud. [Python]
I want to know the population of each country in the world.
How to run the practice code of the book "Creating a profitable AI with Python" on Google Colaboratory
In the python command python points to python3.8
Guidelines for reincarnating in the world of linux programming development (C / C ++ language)
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
I tried to get the authentication code of Qiita API with Python.
Sample code to get the Twitter API oauth_token and oauth_token_secret in Python 2.7
Python code to train and test with Custom Vision of Cognitive Service
Python code to determine the monthly signal of a relative strength investment
[Introduction to Python] Thorough explanation of the character string type used in Python!
I made a program to check the size of a file in Python