[英]Given a sorted list of integers, square the elements and give the output in sorted order
Can anybody help me with this.任何人都可以帮我解决这个问题。 I don't know what am I doing wrong over here
我不知道我在这里做错了什么
list = [-9, -2, 0, 2, 3]
squared_list=[]
for element in list:
squaring = list[element] * list[element]
squared_list.append(squaring)
squared_list.sort()
print(squared_list)
使用squaring = element * element
反对squaring = list[element] * list[element]
因为对于第一个元素,例如,您正在咨询 list[-9] 并且该索引已出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.