リストをパラメーターとして受け取り、リストのどの要素が完全な正方形であるかを判断し、それらの選択要素だけの新しいリストを返すこの python 関数を作成しました。
これが私の機能です:
def square(n):
return n**2
def perfectSquares1(L):
import math
m=max(L)
for n in L:
if type(n) is int and n>0:
Result=map(square,range(1,math.floor(math.sqrt(m))))
L1=list(Result)
L2=list(set(L).intersection(set(L1)))
return L2
しかし今、私はそれを少し作り直そうとしています: n をパラメーターとして受け取り、n が完全平方であれば True を返し、それ以外の場合は False を返す 1 行のブール関数を書きたいと思います。
何かアドバイス?1行だけにする方法がわかりません。