-1

This is part of an assignment. I want to read the input file with ulaz variable and write every 3rd character from that file to the output file. I was thinking about writing the first file to a list and than removing the '\n' firstly. After that, when writing to a new file, I can only think of using [::3] to take every 3rd character. At the moment, I am still struggling with input data. Whenever I write to a lista (list), I get all of the lines but not the first one. I am not sure why this is happening?

ulaz = input("Unesite ime fajla:")
# izlaz = input("Unesite ime fajla:")

with open(ulaz) as existing_file:
    lista = []
    for line in existing_file:
         lista.append([s.rstrip('n') for s in existing_file])
    print(lista)
Matija
  • 69
  • 8

1 Answers1

1

existing_file.read() will give you a string containing all the text in the file. You can then use the subscripting as you mentioned in the question.

ulaz = input("Unesite ime fajla:")

with open(ulaz) as existing_file:
    text = existing_file.read()
    print(text[::3])
Mustafa Quraish
  • 692
  • 4
  • 10