Строка:
для Char в слове возвращает ошибку «TypeError: объект 'int' не повторяется»
Как он стал целым числом, а не строкой?
Как это повторить?
# Write a program that reads a file and prints the letters in decreasing
# order of frequency. Your program should convert all the input to lower
# case and only count the letters a-z. Your program should not count
# spaces, digits, punctuation, or anything other than the letters a-z.
import string
from string import digits
fname = input("Enter file:")
if len(fname) < 1 : fname = "romeo-full.txt"
fhand = open(fname)
charcount = dict()
for line in fhand:
line = line.rstrip()
line = line.lower()
line = line.translate(str.maketrans('','',string.punctuation))
line = str.maketrans("", "", digits)
for word in line:
for char in word:
charcount[char] = charcount.get(char, 0) + 1
print(charcount)
Подробнее здесь: https://stackoverflow.com/questions/591 ... cy-in-file
Python 3, подсчитать частоту букв в файле [дубликат] ⇐ Python
Программы на Python
-
Anonymous
1770830458
Anonymous
Строка:
для Char в слове возвращает ошибку «TypeError: объект 'int' не повторяется»
Как он стал целым числом, а не строкой?
Как это повторить?
# Write a program that reads a file and prints the letters in decreasing
# order of frequency. Your program should convert all the input to lower
# case and only count the letters a-z. Your program should not count
# spaces, digits, punctuation, or anything other than the letters a-z.
import string
from string import digits
fname = input("Enter file:")
if len(fname) < 1 : fname = "romeo-full.txt"
fhand = open(fname)
charcount = dict()
for line in fhand:
line = line.rstrip()
line = line.lower()
line = line.translate(str.maketrans('','',string.punctuation))
line = str.maketrans("", "", digits)
for word in line:
for char in word:
charcount[char] = charcount.get(char, 0) + 1
print(charcount)
Подробнее здесь: [url]https://stackoverflow.com/questions/59187071/python-3-count-letter-frequency-in-file[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия