Answers for "alterning format when reading from a text file"

0

alterning format when reading from a text file

with open("videos.txt") as f:
    lines = [l.strip() for l in f.readlines()]

available_videos = ""
for line in lines:
    title, video, tags = [x.strip() for x in line.split("|")]
    available_videos += f"{title} ({video}) [{tags}]\n"

>>> print(available_videos)
Funny Dogs (funny_dogs_video_id) [#dog , #animal]
Amazing Cats (amazing_cats_video_id) [#cat , #animal]
Another Cat Video (another_cat_video_id) [#cat , #animal]
Life at Google (life_at_google_video_id) [#google , #career]
Video about nothing (nothing_video_id) []
Posted by: Guest on June-30-2021

Code answers related to "alterning format when reading from a text file"

Browse Popular Code Answers by Language