Задача "Кодировщик заголовков". В файле есть список книг. Нужно вернуть абревиатуру. Например "Game of Thrones" ==> "GoT" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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()

25th Dec 2021, 11:37 AM
Bohdan Dovhal
Bohdan Dovhal - avatar
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()
25th Dec 2021, 12:15 PM
Ipang
+ 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()
26th Nov 2022, 6:44 AM
Nebo
Nebo - avatar
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()
8th Nov 2022, 8:18 PM
Стас Горяшин
Стас Горяшин - avatar
- 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()
9th Oct 2022, 7:41 PM
Diamond Samurai
Diamond Samurai - avatar