List printing itself three times over whilst not in a loop

So i am trying to filter some input values in a list, however the output lists are being repeated three times over and i can’t seem to grasp why, any help is appreciated here is the code

initialise the input_list with the given values

input_list1 = [4.7]
input_list2 = [5.2]
input_list3 = [0, 3, 5, 7, 5, 4, 2, 0, -0.2]

initialise the output_list to the empty list

output_list =
out_list2=
list3=

for each input_value of the input_list:

for input_value in (input_list1):
# if the input_value satisfies the condition:
if input_value > 5:
# append the input_value to the output_list
output_list = output_list + [input_value]

for input_value in(input_list2):
if input_value < 6:
out_list2 = out_list2 + [input_value, ]
for input_value in (input_list3):
if input_value > 6 :
list3 = list3 + [input_value]
for input_value in (input_list3):
if input_value < 0:
list3 = list3 + [input_value]

print the output_list

print(output_list)
print(out_list2)

Hi,

Welcome to the forums! :slight_smile:

It’s especially hard to read python code that’s unformatted (and it will behave very differently depending on indentation). If you have time could you re-paste your code? (here’s a link on how to format: [How to] Format code in posts)

Once this is done it’ll be easy for people to chime in and offer their help.

1 Like

[quote=“shanehonnor152134497, post:1, topic:590889”]
So i am trying to filter some input values in a list, however the output lists are being repeated three times over and i can’t seem to grasp why, any help is appreciated here is the code

# initialise the input_list with the given values input_list1 = [4.7] input_list2 = [5.2] input_list3 = [0, 3, 5, 7, 5, 4, 2, 0, -0.2] # initialise the output_list to the empty list output_list = [] out_list2=[] list3=[] # for each input_value of the input_list: for input_value in (input_list1): # if the input_value satisfies the condition: if input_value > 5: # append the input_value to the output_list output_list = output_list + [input_value] for input_value in(input_list2): if input_value < 6: out_list2 = out_list2 + [input_value, ] for input_value in (input_list3): if input_value > 6 : list3 = list3 + [input_value] for input_value in (input_list3): if input_value < 0: list3 = list3 + [input_value] # print the output_list print(output_list) print(out_list2)

If you execute your code above, you’ll get the following output:

[]
[5.2]

Is this the output you’re looking for?