0

How to create a list consisting of the negative values in the last numbers. Associate the new list with the variable negtives.

29th Oct 2016, 10:21 PM
lil_gibby
3 Réponses
0
can't fully understand what you mean if you have some list with numbers and you want to create another list with negatives of that numbers, you can do something like this: list1 = [1, 2, 3] #your first list list2 = list() #creating new empty list for n in list1: #going through first list list2.append(-n) #adding negative item
29th Oct 2016, 10:31 PM
Demeth
Demeth - avatar
0
I meant list numbers not last. thanks for your input. I have a negative list and can't figure out how to make the new list with negative numbers
29th Oct 2016, 10:57 PM
lil_gibby
0
list1=[-1,_2,_3,0,1,2,3] list2=[] for num in list1: if num<0: list2.append(num) print(list2)
30th Oct 2016, 6:40 AM
Naveen Singh Negi
Naveen Singh Negi - avatar