Question: I am trying to replace items in list of lists by the value of the index of that specific list. I can do it with a for loop, but I was wondering if there is a faster way to do this.

such that the following list

```
example = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

```

becomes:

```
solution = [[0, 0, 0], [1, 1, 1], [2, 2, 2]]

```

Answer: 
Your way with `for` loop should work, but if you want another way in a short version then you can do it this way with [list comprehension](https://www.programiz.com/python-programming/list-comprehension) and [enumerate](https://www.programiz.com/python-programming/methods/built-in/enumerate),

```
example = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
result = [[index] * len(value) for index, value in enumerate(example)]
print(result)

```
List comprehensions are usually faster than loops

Here is a solution with list comprehensions

```py
example = [[1,2,3],[4,5,6],[7,8,9]]
solution = [[x for _ in range(len(example[x]))] for x in range(len(example))]
print(solution)

```

```
Output
[[0, 0, 0], [1, 1, 1], [2, 2, 2]]

```