0
I've been trying to create a program to convert an file with the text 'iinnpppuuutt' to a file with the text 'i2n2p3u3t2'. Can someone give me an example?
3 Respuestas
+ 3
check this
def g(k):
s=""
u=""
n=0
for i in tuple(k):
if i==u:
n+=1
else:
if u!="" : s+=u+str(n)
n=1
u=i
s+=u+str(n)
return s
x=input("File path to input : ")
y=input("File path to output : ")
print()
try:
f1=open(x,"r")
except:
print("Reading file open error")
exit()
s=""
for t in f1.readlines():
s+=g(t)
f1.close()
try:
f2=open(y,"w")
except:
print("Writing file open error")
exit()
f2.writelines(s)
f2.close()
print("Done!")
+ 2
well this works
(when using android path should be like /storage/sdcard0/w.wee )
from itertools import groupby as g
x=input("File path to input : ")
y=input("File path to output : ")
print()
try:
f1=open(x,"r")
except:
print("Reading file open error")
exit()
s=""
for t in f1.readlines():
x=g(t)
for i,j in x:
s+=i+str(len(list(j)))
f1.close()
try:
f2=open(y,"w")
except:
print("Writing file open error")
exit()
f2.writelines(s)
f2.close()
print("Done!")
input example:
File path to input : /storage/sdcard0/w.wee
File path to output : /storage/sdcard0/w.wee
output:
Done!
0
Can I also do this without importing functions?