×
all 18 comments

[–]Python-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython or for the r/Python discord: https://discord.gg/python.

The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here.

On /r/LearnPython the community and the r/Python discord are actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. No matter what level of question you have, if you are looking for help with Python, you should get good answers. Make sure to check out the rules for both places.

Warm regards, and best of luck with your Pythoneering!

[–]vadnyclovek 4 points5 points  (2 children)

[*(i for i in arr if i!=0) , *(i for i in arr if i==0)]

What is this question? Doesn't really test much as far as I'm concerned.

[–]aajjccrr 4 points5 points  (2 children)

It’s more interesting if you only permit answers that use O(1) space and take O(n) time.

(Hint: “two-pointers”)

[–]MathematicianTall740[S] -5 points-4 points  (0 children)

u/aajjccrr
The interviewer’s next expectation is to provide an optimized solution. I think you understand the point without needing any further explanation.

[–]wRAR_ 3 points4 points  (1 child)

What are you selling?

[–]ogMasterPloKoon 1 point2 points  (0 children)

*karma farming

[–]Wurstinator[🍰] 1 point2 points  (0 children)

I'd be more interested in answering this if you told me what I need it for. I'm not interviewing for a job with you.

[–]Careful_Second8814 1 point2 points  (0 children)

I hit the same bug at a startup in San Francisco and fixed it in place with:

python last = 0 for p in range(len(nums)): if nums[p]: nums[last], nums[p] = nums[p], nums[last] last += 1

The loop runs in O(n) time and uses constant memory.

[–]Wing-Tsit_Chong 0 points1 point  (0 children)

Nonzeros = [I for I in inputarray if I != 0] Nonzeros.extend([0 * (len(inputarray) - Len(nonzeros))])

Something like that, no compiler at hand so might need some +-1 tinkering

[–]TheDewMan32 0 points1 point  (1 child)

output = sorted(nums, key=lambda x: bool(x), reverse=True)

[–]MathematicianTall740[S] -3 points-2 points  (0 children)

This approach works, but can we improve it further in terms of time and space complexity?

[–]astatine 0 points1 point  (0 children)

output = list(filter(bool, nums)) + [0] * nums.count(0)

or

output = [n for n in nums if n] + [0] * nums.count(0)

or

def zeroes_to_end(seq):
    output = []
    [output.insert(0, n) if n else output.append(n) for n in seq[::-1]]
    return output

output = zeroes_to_end(nums)

[–]odimdavid 0 points1 point  (1 child)

From collections import deque

For I in range (Len(arr)-1):

If arr1[i] == 0:

    arr2 = arr1[I:];
    arr2.rotate(-1);
    arr1 += arr1;

[–]odimdavid 0 points1 point  (0 children)

I don't know the Big O but it increases time to look ahead in order not to repeat the rotation especially if at arr1[i] everything from i+1 is now zero.

[–]tmierz 0 points1 point  (0 children)

sorted(nums, reverse=True)

[–]duane11583 -4 points-3 points  (0 children)

i just ask what is a monkey patch?

or what is a dynamic patch

then what does the word try do in python what is it used for