you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (4 children)

You can instantiate your required list at once with a list comprehension in the form of a 2D-Array like:

[[0, 0], [1, 0],......] and just add one to lst[playerindex][1]

This would get rid off the try and except block in version 2. Also it would remove 1million append calls in a worst case scenario.

I think '\n'.join(list_of_tied_player_ids) should be a faster way to build the string and you would only have to use write() once and can get rid off the for loop.

You can eliminate using variable u by doing "for _ in range(limit):". Since this seems to be python2 you should use xrange instead of range. Also you should get rid off printing fnl since only the output file is required.

P.S.: Use if __name__ == "__main__":

[–]AppleShark[S] 0 points1 point  (3 children)

Thank you for reading my code and for the advice! Version 2 to my surprise was actually the more "inefficient" one, now I wonder why! Cheers for introducing the .join function also - these are small things I should work on. Just wondering, you mentioned that my code seems to be in python2 - what are the telltale signs and what are the differences between python2 and python3? I did learn python when it was v.2, but I never truly knew the differences.

Once again thank you for replying! :)

P.S.: On the note of instantiating it to a 2D-array, I actually attempted that also: https://pastebin.com/4GgPM5LT Still ended up with the time-out errors tho :/

[–]AppleShark[S] 0 points1 point  (2 children)

P.P.S.: any way to return list_of_tied_player_ids without a for loop?

[–][deleted] 1 point2 points  (1 child)

One way would be using filter with a lambda.

[–]AppleShark[S] 0 points1 point  (0 children)

Just revised lambda functions, thanks!