1

I have a python script which loads a list of strings (very long list) into an array. I need to perform several operations on each element of the array. There are three operations that I need to do on each element: (1) count the length of the string, (2) multiply that by a scalar, and (3), take a mod of that.

This is very-very simple to do using a loop, but because I have so many elements in my array, I am wondering if there is a better way to do this that a simple for loop. I need it to be fast, and looping through millions of elements doesn't seem like the most efficient way to manage this.

Does anyone know of any way to optimize the performance in this kind of scenario using Python? Threading? Or is there an array iterator operator that I might not have heard of?

(I know this sounds like a homework problem, but it's not, I assure you. It's just a very simplified version of what I need to accomplish).

Any advice would be most appreciated! Thanks!

1 Answer 1

5

It must be done with a loop. Use a faster loop.

n = [len(x) * k % m for x in S]
Sign up to request clarification or add additional context in comments.

1 Comment

This is interesting. I'll give it a shot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.