+ 1
Задача "Кодировщик заголовков". В файле есть список книг. Нужно вернуть абревиатуру. Например "Game of Thrones" ==> "GoT"
Помогите дополнить или исправить код. file = open("/usercode/files/books.txt", "r") #ваш код result = list() lines = file.readlines() for line in lines: s = line.split() for i in s: word = "" word += i[0] result.append(word) print(result) file.close()
4 Answers
+ 2
Please put Python inside the tags ☝
file = open("/usercode/files/books.txt", "r")
#ваш код
lines = file.readlines()
result = [ "".join( tuple( w[0] for w in line.split() ) ) for line in lines ]
print(result)
file.close()
+ 1
✅Это ЕДИНСТВЕННЫЙ рабочий код!!
file = open("/usercode/files/books.txt", "r")
#ваш код
lines = file.readlines()
result = [ "".join( tuple( w[0] for w in line.split() ) ) for line in lines ]
for i in result:
print(i)
file.close()
0
file = open("/usercode/files/books.txt", "r")
#ваш код
f = file.readlines()
for i in f:
s = i.split(" ")
code = ""
for x in s:
code += x[0]
print(code)
file.close()
- 1
file = open("/usercode/files/books.txt", "r")
for line in file.readlines():
#ваш код
x = line.split(" ")
y = len(x)
z = list(x)
for l in range(y):
r = list(z[l])
print(r[0])
file.close()