Reputation: 27
I am using the following code to print the list of friends in twitter
users = api.friends()
print([u.name for u in users])
I get the following output
['The New York Times', 'BBC Breaking News', 'Oprah Winfrey']
But I want something like this
['The New York Times',
'BBC Breaking News',
'Oprah Winfrey' ]
Upvotes: 1
Views: 4323
Reputation: 81
Hope below works
import pprint
users = api.friends()
pprint.pprint([u.name for u in users], width=1)
Upvotes: 1
Reputation: 36
Do you need to keep the list brackets, quotes, and commas? If you just want to print the items one per line, you could do something like:
print(*[u.name for u in users], sep='\n')
Or you could loop and print each item individually:
for u in users:
print(u.name)
Upvotes: 2
Reputation: 4674
Just break the code, Write loop and then print each name
for u in users:
print u.name
print ""
Upvotes: 2