IT高手
小弟又有問題了,我想將
X=[1,2,3,4,5,6,7,9] 分別加上1,2,3,4,5以及減掉1,2,3,4,5,並且過濾小於0以及大於10的元素,組成新的不重複元素的List.
新List = [1,2,3,4,5,6,7,9,2,3,6,8,......]
For i in X:
1st = i+1:
2nd = i+2:
我只會這總笨方法,希望有IT高手教我該如何寫
謝謝
def helper(x):
add_list=[-1,-2,-3,-4,-5,1,2,3,4,5]
ans=[]
for i in x:
for j in add_list:
ans.append(i+j)
return list(set([k for k in ans if k>=0 and k<=10]))