I have a function that takes into the terminal during operation:
print ( "" "" ") I need to ensure that each new print numbered:
Print ( "" "[1] ..." ") Pre>
question@mail.ru
·
01.01.1970 03:00
I have a function that takes into the terminal during operation:
print ( "" "" ") I need to ensure that each new print numbered:
Print ( "" "[1] ..." ") Pre>
answer@mail.ru
·
01.01.1970 03:00
The built -in function is exactly what you need!
It retus the motorcade with the serial number and the next element:
& gt; & gt; & gt; seasons = [ 'spring' , 'summer' , 'fall' , 'Winter' ] & gt; & gt; & gt; line ( enumerate (seasons)) [( 0 , '"spring' ), ( 1 , 'summer' ), ( 2 , 'fall' ), ( 3 , 'winter' )] The numbering can be read from a given number (0 by default):
& gt; & gt; & gt; lim ( enumerate (seasons, start = 1 )) [( 1 , 'spring' ), ( 2 , 'summer' ), ( 3 , 'fall' span>) ( 4 , 'winter' )]for your case:
Pre>MONTHS = [ 'January' , 'february' , '' march ', 'April' , 'May' , 'june' , 'july' , 'August' , 'september' , 'october' , '' "november ', 'December' ] for i, m in enumerate (months, 1 ): # read the numbering with 1 print ( f ': {m} ') to print:
: May 6 : june 7 : july 8 : auugust 9 : september 10 : october 11 : november 12 : December1 : january 2 : february 3 : march 4 : april5 or like this:
PrinT ( f '[ {i} ] {m} ' )will lead to your template:
[ 1 ] January [ 2 ] february [ 3 ] march [ 4 ] april [ 5 ] May [ 6 ] june [ 7 ] July [ 8 ] august [ 9 ] september [ 10 ] october [ 11 ] november [ 12 ] December PRE>