I have a list of objects stored in socialmedias
variable. One parameter of SocialMedia class is called username
. I want to create an array with all usernames from that list of objects socialmedias
and I want to be sure I use the best way.
socialmedias = [obj1, obj2, obj3, ..., objN]
usernames = []
for sm in socialmedias:
usernames.append(sm.username)
print(usernames)
>> [username1, username2, username3, ..., usernameN]
Is there any other way to do it in less line of codes I used above?