There are two text files ( test.txt , test1.txt ). The first contains one version of the Russian translation, and the second contains a translation for various languages, including Russian.
(test.txt) Крушите всё! Нет! Вот, значит, до чего всё дошло… (test1.txt) Destroy everything!! ¡¡Destruyámoslo todo!! Руби и круши! Zerstört alles. Cassez tout ! Distruggi tutto!! Destrua tudo!! No!! And so it has come to this… ¡¡No!! Ya hemos llegado a esto... Нет! Вот, значит, до чего все дошло… Nein!! Euer Ende ist nah ... Non !! Tout ça pour en arriver là... No!! E quindi siamo arrivati a questo... Não!! E, assim, chegou a isso… There are also dictionaries with the alphabet of numbers, whitespace-characters, Russian and English.
The question is how to replace the lines with the Russian language from the second file with the lines from the first?
Here are the best practices:
eng = [ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S', 'T','U','V','W','X','Y','Z', 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s', 't','u','v','w','x','y','z', '0','1','2','3','4','5','6','7','8','9', '!','"','#','$','%','&','\'','(',')','*','+',',','- ','.','/',':',';','<','=','>','?','@','[','\\',']','^','_','`','{','|','}','~'] rus = [ 'А','Б','В','Г','Д','Е','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т', 'У','Ф','Х','Ц','Ч','Ш','Щ','Ы','Э','Ю','Я', 'а','б','в','г','д','е','ж','з','и','й','к','л','м','н','о','п','р','с','т', 'у','ф','х','ц','ч','ш','щ','ы','э','ю','я'] symbols = [ '0','1','2','3','4','5','6','7','8','9', '!','"','#','$','%','&','\'','(',')','*','+',',','- ','.','/',':',';','<','=','>','?','@','[','\\',']','^','_','`','{','|','}','~'] srus = set(rus) seng = set(eng) ssym = set(symbols) sl = lambda a,b: a.intersection(b) a1 = [] a2 = [] with open(u'test1.txt','r',encoding='utf-8') as fdata, open('test.txt','r',encoding='utf-8') as sdata: for i,v in enumerate(fdata): value = [j for j in v] value = [j.replace('\n','') for j in value] svalue = set(value) a1.append(''.join(value)) for i,v in enumerate(sdata): value = [j for j in v] value = [j.replace('\n','') for j in value] svalue = set(value) if sl(srus,svalue) | (sl(srus,svalue) & sl(seng,svalue)) | (sl(srus,svalue) & sl(ssym,svalue)): #если есть рус., англ. и прочие символы a2.append(''.join(value)) else: pass
test1.txt) file there is both Russian and other languages. - CockLobster