'Select all lines if occurence for one char in vscode
i'm going straight to the point; First of all i'm trying to select all lines if i find one char in common e.g:
-"activit�"
-"activit�s"
-"actrice"
-"actualisation"
I'd like to select all lines where � is present, then i'd like to make a python script removing all words who have less or more than 5 chars
with open("liste_francais.txt") as mot:
for a in readlines(mot):
if len(a)!=5:
a.replace(a, "")
this is my code atm but its not working, may i get help ? :)
Solution 1:[1]
import unidecode #e.g. é -> e
lst=[]
with open("liste_francais.txt") as file:"""opening txt file and getting each item from it"""
lines=file.readlines()
for a in lines:
if len(a)==6:"""\n adds up one char so if u want n chars do n+1"""
lst.append(a)
textfile = open("a_file.txt", "w")"""new txt file"""
for element in lst:
element = unidecode.unidecode(element)"""é to e"""
textfile.write(element.upper()+"\n")"""upper for readibility"""
textfile.close()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |