Improving efficiency of staged transformations

Staged transformations are transformations applied to a set of data in stages.

Lets say I want the following to happen.

Given a list [1,2,3,4,5,…, 100]

1. Square all odd numbers

2. Cube all even numbers

3. Let the numbers from the above calculations should be stored in 1 list.

Hence we should get [1, 8, 9, 64, 25, …]

4. Now in this list add 3 to all even numbers and 2 to all odd numbers

Final o/p: [3,11,11,67,27,…]

We can simplify the code a lot…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: