>>> lst = [1, 2, 3]
>>> print('\n'.join('{}: {}'.format(*k) for k in enumerate(lst)))
0: 1
1: 2
2: 3
Note: you just need to understand that list comprehension or iterating over a generator expression is explicit looping.
More Related Contents:
- Is there a way to ordinate numbers in a list?
- finding the biggest sequence of repeating numbers in a list
- How to append new line to the list
- Remove duplicate dict in list in Python
- How to efficiently compare two unordered lists (not sets) in Python?
- Finding max value in the second column of a nested list?
- Why does foo.append(bar) affect all elements in a list of lists?
- list to dictionary conversion with multiple values per key?
- How to get the nth element of a python list or a default if not available
- Python – TypeError: ‘int’ object is not iterable
- Why doesn’t list have safe “get” method like dictionary?
- Explicitly select items from a list or tuple
- Does python have a sorted list?
- Summing elements in a list
- “unstack” a pandas column containing lists into multiple rows [duplicate]
- How to make a custom object iterable?
- How to access the elements of a 2D array?
- Why does a for-loop with pop-method (or del statement) not iterate over all list elements [duplicate]
- How to create a list of objects?
- Why does using multiplication operator on list create list of pointers? [duplicate]
- Remove dictionary from list
- Determine if 2 lists have the same elements, regardless of order? [duplicate]
- How do I extract all the values of a specific key from a list of dictionaries?
- Iterate through adjacent pairs of items in a Python list [duplicate]
- creating a defaultlist in python
- Converting list to *args when calling function [duplicate]
- Column of lists, convert list to string as a new column
- Python and SQLite: insert into table
- Creating a list in Python with multiple copies of a given object in a single line
- How can I turn a flat list into a 2D array in python?