Not sure how to create a python function for this. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Not sure how to create a python function for this.

I have a list Eg. Y=([123,4325,1234,34567],[123,3425,532,3456],etc) Result = [i for i in Y if i[0]<i[1]<i[2]<i[3]] Print(Result) It will give the result that I want for only 4 element For this portion i[0]<i[1]<i[2]<i[3]] , I will like to have it change to whatever I wanted the amount of element using input instead of just 4 elements Any suggestions?

10th Nov 2020, 3:34 PM
hui hui
hui hui - avatar
2 Answers
+ 3
Maybe this is what you are looking for Result = [i for i in Y if all([i[j]<i[j+1] for j in range(len(i)-1)])] print(Result)
10th Nov 2020, 4:18 PM
Abhay
Abhay - avatar
0
Thanks. What about I wanted to change into a def function for the below. Result = [i for i in Y if i[0]<i[1]<i[2]<i[3]] Print(Result)
12th Nov 2020, 1:23 PM
hui hui
hui hui - avatar