It returns None. How to assign to video_list the list values?
video_list = [print(video.title) for video in videos]
EDIT : The process to get videos list is very long , that's why I asked for
It returns None. How to assign to video_list the list values?
video_list = [print(video.title) for video in videos]
EDIT : The process to get videos list is very long , that's why I asked for
You should not print. Just get the value video.title
. So answer video_list = [video.title for video in videos]
video_list = [video.title for video in videos]
You can't use print in a list comprehension. Now you will have all values in video_list
and you can print it as a list to see the values print(video_list)
Since print
returns None
, you could use or
to return the value after printing, but this is not recommended.
video_list = [print(video.title) or video.title for video in videos]
It is better to first create the list, then print it after.
It would be more readable to keep assigning and printing apart:
video_list = [video.title for video in videos]
print(*video_list, sep='\n')