Home > Net >  Redeclared 'descending_list' defined above without usage Pycharm warning
Redeclared 'descending_list' defined above without usage Pycharm warning

Time:04-13

I'm creating an ascending_list (no problem) and a descending_list (it's giving warning).

# Input: '7 21 -14'
ascending_list = descending_list = [int(num) for num in input().split()]
ascending_list.sort()  
descending_list = ascending_list.copy()  # WARNING HERE!!!
descending_list.sort(reverse=True)

print(ascending_list)  # [-14, 7, 21]
print(descending_list)  # [21, 7, -14]

CodePudding user response:

It gives you warning Redeclared 'descending_list' defined above without usage because you are declaring descending_list in first line, but not using it anywhere before line 3.

CodePudding user response:

to not get a warning first initial lista_decrescente then refer a copy of it to lista_crescente

Code:

lista_decrescente = [int(num) for num in input().split()]
lista_crescente = lista_decrescente.copy()
lista_crescente.sort()
lista_decrescente.sort(reverse=True)

print(lista_crescente)
print(lista_decrescente) 

output:

with input 7 21 -14 result will be:

[-14, 7, 21]
[21, 7, -14]
  • Related