S
S
sparr0w12021-07-09 01:48:39
Python
sparr0w1, 2021-07-09 01:48:39

How to display a list with the order of the elements?

You need to output a list like this:

1.  home
2.  watermelon

etc

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2021-07-09
@sparr0w1

print('\n'.join(f'{i}. {n}' for i, n in enumerate(arr, 1)))

L
lerotyck, 2021-07-09
@lerotyck

s = ['home', 'watermelon', 'apl', 'banana']
for i in range(1, len(s) + 1):
    print(i, ".  ", s[i-1])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question