What should I do if I want to display a list like below using python's for statement and range function as if it were after plastic surgery?If it's the simplest and easiest way to understand, I don't care.
Before plastic surgery
[('Candidate is jerk, alleges rival', 338647), ('Bears love berries, alleges bear', 253801), ('Bad things gone, say good people', 170098)]
After plastic surgery
"Candidate is jerk, allegesrival" — 338647 views
"Bears love berries, alleges bear" — 253801 views
"Bad things go, say good people" — 170098 views
I don't know if it's simple or not, but I wrote it in the list.
range
is not often used if the original is a list.
data=[('Candidate is jerk, alleges valid', 338647),('Bears love berries, alleges bear', 253801),('Bad things gone, say good people', 170098)]
[print('%s' - %d views'%(d[0], d[1])) for ind data]
#-*-coding:utf8-*-
defmain()->None:
data=[('Candidate is jerk, allegesrival', 338647),('Bears love berries, alleges bear', 253801),('Bad things gone, say good people', 170098)]
for article, view in data:
print(f'"{article}" —{view} views')
if__name__=='__main__':
main()
© 2024 OneMinuteCode. All rights reserved.