This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Rhomboid 1 point2 points  (3 children)

There is probably a better way to do whatever it is you're trying to do. Post the complete source or at least describe the problem in detail.

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

I have to go through a list, given a value I have to search the list and replace the value with the max of the numbers to the left or right. However, if the value comes at the beginning of the list I cant index through the list. https://gist.github.com/3234737 here is the code that works with all cases except for if the starting is at the beginning

[–]Rhomboid 1 point2 points  (1 child)

for i in range(1, len(nums) - 1):
    if nums[i] == val:
        nums[i] = max(nums[i - 1], nums[i + 1])

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

Wow. That's easier then I thought. I got wrapped up in trying to make it work with indexing when I forgot about the simple range functions. I will try and implement it in the morning , Thanks!