Find to Positions of Characters and How Many Times Used in Text with Python

user12613456

I wanna make a table about positions of characters in a text. Example:

Text = "an apple and a banana"

Char:Positions(from 0 to 20) and how many times used in this positions

Characters--> A:4101010...0-B:100000...0-C:000000...0-D:001000...0-E:000010...0-...-Z:000000...0

What is wrong?

position_list = []

i = 0
for char in range(29):
    position_list.append([])
    for position in range(20):
        position_list[i].append(0)
    i += 1


alphabet = ["a", "b", "c", "ç", "d", "e", "f", "g", "ğ", "h", "ı", "i", "j", "k", "l", "m", "n", "o", "ö", "p", "r", "s", "ş", "t", "u", "ü", "v", "y", "z"]
alphabet_index = 0
text = ["sample", "text"]

for word in text:
    x = 0
    for char in alphabet:
        start = 0
        while len(word) > start:
            char_pos = word.find(char, start)
            start += 1
            if char_pos == -1:
                break
            else:
                position_list[x][char_pos] += 1
        x += 1

print(position_list)
Riccardo Bucco

This solves your problem:

alphabet = ["a", "b", "c", "ç", "d", "e", "f", "g", "ğ", "h", "ı", "i", "j", "k", "l",
            "m", "n", "o", "ö", "p", "r", "s", "ş", "t", "u", "ü", "v", "y", "z"]

position_list = [[0]*20 for i in range(len(alphabet))]

text = "an apple and a banana"

for word in text.split():
    for i, c in enumerate(word):
        position_list[alphabet.index(c)][i] += 1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to find how many times a code was used in the past 5 years

From Java

How to count how many times characters appearing in a text?

From Dev

Find how many times the text in one line repeats in another

From Dev

Python How many times each meta keyword is used in a string

From Dev

Counting how many times a base function is being used, Python

From Dev

Find specific text, in line above this text insert characters at set positions

From Java

Find out how many times a regex matches in a string in Python

From Dev

Find how many times changes maximum value in a list with reduce() (Python)

From Java

How many times the word is used on the html page

From Dev

Is there a formula that will count how many times "@" is used in a cell?

From Dev

How can I find the positions from characters in a string with string::find?

From Dev

How can I read in values from a text file and calculate how many times a value repeats and then find the average?

From Dev

How to find how many times X appears

From Dev

Find common elements of two strings including characters that occur many times

From Dev

Counting how many times I used one equation until it reaches a specific result in python

From Dev

Count how many times a list of characters appear in a string - Python (no count or counter)

From Dev

Find how many times a pair of values occurs

From Dev

Find how many times numbers appear in array

From Dev

How to find missing values positions in python?

From Dev

How to find a sequence of positions of a moving object in Python?

From Dev

How to find index positions of a substring using Python

From Dev

How to find how many times the first letter is repeated in a string using Python?

From Dev

How do I find duplicates in an array and display how many times they occurred python?

From Dev

How to count how many times a global variable was used (read and write)?

From Dev

How to find the used characters in a subsetted font?

From Dev

Need to find how many times a letter appears. (python3)

From Dev

Does MongoDB track how many times each index is used in a query?

From Dev

PHP Count how many times code is used on a page

From Dev

Counting how many times the click() function has been used

Related Related

  1. 1

    How to find how many times a code was used in the past 5 years

  2. 2

    How to count how many times characters appearing in a text?

  3. 3

    Find how many times the text in one line repeats in another

  4. 4

    Python How many times each meta keyword is used in a string

  5. 5

    Counting how many times a base function is being used, Python

  6. 6

    Find specific text, in line above this text insert characters at set positions

  7. 7

    Find out how many times a regex matches in a string in Python

  8. 8

    Find how many times changes maximum value in a list with reduce() (Python)

  9. 9

    How many times the word is used on the html page

  10. 10

    Is there a formula that will count how many times "@" is used in a cell?

  11. 11

    How can I find the positions from characters in a string with string::find?

  12. 12

    How can I read in values from a text file and calculate how many times a value repeats and then find the average?

  13. 13

    How to find how many times X appears

  14. 14

    Find common elements of two strings including characters that occur many times

  15. 15

    Counting how many times I used one equation until it reaches a specific result in python

  16. 16

    Count how many times a list of characters appear in a string - Python (no count or counter)

  17. 17

    Find how many times a pair of values occurs

  18. 18

    Find how many times numbers appear in array

  19. 19

    How to find missing values positions in python?

  20. 20

    How to find a sequence of positions of a moving object in Python?

  21. 21

    How to find index positions of a substring using Python

  22. 22

    How to find how many times the first letter is repeated in a string using Python?

  23. 23

    How do I find duplicates in an array and display how many times they occurred python?

  24. 24

    How to count how many times a global variable was used (read and write)?

  25. 25

    How to find the used characters in a subsetted font?

  26. 26

    Need to find how many times a letter appears. (python3)

  27. 27

    Does MongoDB track how many times each index is used in a query?

  28. 28

    PHP Count how many times code is used on a page

  29. 29

    Counting how many times the click() function has been used

HotTag

Archive