-1

I'm gonna convert this :

1
00:00:01,710 --> 00:00:03,830
Now react came out in 2013.

2
00:00:03,840 --> 00:00:07,890
But what do we have before then before we act.

3
00:00:07,890 --> 00:00:15,040
Well the front fronting landscape was very different initially back in the 90s and early 2000s.

to something like this :

thisdict = {
  "1": "Now react came out in 2013.",
  "1time": '00:00:01,710 --> 00:00:03,830'
}

can anyone help?

giant
  • 93
  • 7
  • What have you tried so far? This seems like a simple "read a file line by line and operate on them" deal. – AKX May 31 '21 at 09:19

1 Answers1

2

Do you mean something like this?

with open('subtitle.srt') as file:
    subtitle = file.readlines()
    
    sub_list = [subtitle[i : i+4] for i in range(0, len(subtitle), 4)]
    
    this_dict = {}
    
    for item in sub_list:
        number = item[0].strip('\n')
        this_dict[number] = item[2].strip('\n')
        this_dict[f"{number}time"] = item[1].strip('\n')
        
    print(this_dict)

Output :

{'1': 'Now react came out in 2013.', '1time': '00:00:01,710 --> 00:00:03,830', '2': 'But what do we have before then before we act.', '2time': '00:00:03,840 --> 00:00:07,890', '3': 'Well the front fronting landscape was very different initially back in the 90s and early 2000s.', '3time': '00:00:07,890 --> 00:00:15,040'}
Haze
  • 147
  • 9