Form a list of pythons with a for statement and a range function

Asked 2 years ago, Updated 2 years ago, 44 views

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

python python3

2022-09-30 20:16

2 Answers

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]


2022-09-30 20:16

#-*-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()


2022-09-30 20:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.