May-17-2019, 09:58 PM
Well, let's start at the top...
2) Multiple replace operations might look better (?) as a regex, since it'd only be one line, and one operation.
(May-13-2019, 04:50 PM)sunhyunshine Wrote:1)def atidarymas(): #funkcija, atidaromas duomenu failas, panaikinami taskai, kableiai failas = open("duomenys.txt", "r") duomenys = failas.read() duomenys = duomenys.replace("\n", "") duomenys = duomenys.replace(".", "") duomenys = duomenys.replace(",", "") sar = duomenys.split() failas.close() return (sar)
with
blocks are a good habit to get into, so the resource gets closed automatically when you're done with it (so you don't have to worry about forgetting to clean up after yourself).2) Multiple replace operations might look better (?) as a regex, since it'd only be one line, and one operation.
import re def atidarymas(): #funkcija, atidaromas duomenu failas, panaikinami taskai, kableiai with open("duomenys.txt", "r") as failas: duomenys = failas.read() sar = re.sub(r"[\n.,]", "", duomenyx).split() return sar