I would like to use Python 3.6 to create a function that changes the output according to the contents of the given array.
input_data=[1,2,3]
defequ(x):
Value for each element of ifx > 2:
return x +3
else:
return x+1
Expected output for equ(input_data): [2,3,6]
How do we create these functions?
If not, how can I code efficiently?
Thank you for your cooperation
python python3
Spinning each element of the array with for would be good.
input_data=[1,2,3]
defequ(x):
result = [ ]
for e in x:
if > 2:
result.append(e+3)
else:
result.append(e+1)
return result
print(equ(input_data))
A function that receives each element of the array, not the array itself, can be more concise.
input_data=[1,2,3]
print(list(map(
lambdax: x +3 if x > 2 else x +1,
input_data,
)))
540 Uncaught (inpromise) Error on Electron: An object could not be cloned
550 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
728 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
548 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.