PROGRAMMING:Weighted sum of list number elements (1)
Enter a nested list with unlimited nesting levels, and calculate the weighted sum of list elements according to the levels. Each element of the first layer
The value of is: element value \ * 1, the value of each element in the second layer is: element value \ * 2, and the value of each element in the third layer is: element value \ * 3,
... and so on!
###Input format:
Enter the list on one line
###Output format:
Output the weighted sum on one line
###Input example:
Here is a set of inputs. For example:
```in
[1,2,[3,4,[5,6],7],8]
```
###Output example:
The corresponding output is given here. For example:
```out
seventy-two
```
answer:If there is no answer, please comment
```
from collections import Iterable
def flatten(items,level):
for x in items:
if isinstance(x,Iterable):
yield from flatten(x,level+1)
else:
yield x*level
items=eval(input())
l=[x for x in flatten(items,1)]
print(sum([x for x in flatten(items,1)]))
```
The value of is: element value \ * 1, the value of each element in the second layer is: element value \ * 2, and the value of each element in the third layer is: element value \ * 3,
... and so on!
###Input format:
Enter the list on one line
###Output format:
Output the weighted sum on one line
###Input example:
Here is a set of inputs. For example:
```in
[1,2,[3,4,[5,6],7],8]
```
###Output example:
The corresponding output is given here. For example:
```out
seventy-two
```
answer:If there is no answer, please comment
```
from collections import Iterable
def flatten(items,level):
for x in items:
if isinstance(x,Iterable):
yield from flatten(x,level+1)
else:
yield x*level
items=eval(input())
l=[x for x in flatten(items,1)]
print(sum([x for x in flatten(items,1)]))
```