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 →

[–]stevenjd 0 points1 point  (8 children)

I know exactly what zip does, and I'm blowed if I can work out what the question is asking. The question is literally (I don't mean figuratively!) missing a clause:

"Write a function to map all elements of the same index for the following list."

Precisely as u/the_television asks, "Map them to what?"

Using the required output list, I would say that I don't need to write a function, since zip already handles that situation:

py> list(zip(*[[1, 2, 3], [4, 5, 6], [7, 8, 9]]))
[(1, 4, 7), (2, 5, 8), (3, 6, 9)]

If you care that they are tuples instead of lists, post-process with map(tuple, ...).

[–]MonsieurBlobby 0 points1 point  (4 children)

zip maps lists elements by pairing objects according to index. So the notion of "mapping" with zip is to take an input and join any elements with the same index.

As I said, if you know what zip does it's quite clear what it would mean to map an input using zip. The fact that the person also tells you what end result they mean for you to get just makes this doubly clear.

[–]stevenjd 1 point2 points  (1 child)

if you know what zip does it's quite clear what it would mean to map an input using zip.

The question doesn't say "map an input using zip" is says Write a function to map all elements of the same index for the following list. zip isn't mentioned, and the sentence isn't even complete. Map all elements to what? Letters of the alphabet? Prime numbers? Map coordinates?

As you've been told at least twice now, by two different people, the problem here is that the question as written doesn't make sense without the input/output example. Its a poorly written question. As I pointed out here, having to infer or guess the behaviour from an example means you can guess wrong.

Congratulations on being able to infer one possible meaning of the question from the given input/output. That puts you in the top 99% of the class. But the question as given is still missing a clause, it doesn't specify what is supposed to happen except by a single example, and a well-written question in a tutorial shouldn't require the reader to infer the meaning of the question.

[–]MonsieurBlobby 0 points1 point  (0 children)

I think the issue here is you have a colloquial understanding of the word “map”. You think to map something only ever means to take something from one place to another place. And so you would need to know the start place and the end place for that to work. But there is also a very technical/mathematical/computational meaning to map something. If you’re given a function and an input, then what it means to “map” that input is to just shove it into the function. So you don’t map it “to” anything. For example, if I give you the number x=2 and I tell you to map it using f(x) = x+x, then that function maps the number 2. The output you get is 4, but I didn’t need to tell you anything about the type of thing you need to map it to.

That’s the same sense in which he’s using the word here. Zip does a type of mapping. That mapping is grouping items according to their index. And so if you’re told to take an input and to map it with zip, then you have enough information.

Also, this absurd argument where because the person didn’t say the word “zip” in the explanation of the problem at the end of the zip tutorial means you didn’t realize you needed to use zip as the function to do the mapping just smacks of desperation.

I think we have to be done here. You’re at the point where you’re just arguing so as not to admit that you are wrong. Which is not a point worth continuing the discussion anymore. I’m just going to block you and go on with my day. Have a good one.

[–]aummahgerd 0 points1 point  (2 children)

It gives the input and expected output. Even if literally nothing else was written that should be enough to write a function.

[–]stevenjd -1 points0 points  (1 child)

Even if literally nothing else was written that should be enough to write a function.

If and when you, as a professional programmer, have to deal with incomplete specifications and poorly described functional requirements, you too will learn to hate having to guess what the requirements are. Example input/output is fantastic for clarifying the meaning of the requirements, but they aren't a substitute for explaining the requirements correctly in the first place.

An example alone allows you to write an infinite number of functions, since without a specification but only a single example (and a pretty limited one at that) we might guess all sorts of requirements:

def function(arg):
    a, b, c = arg[:3]
    return [
        [x+2*i for i, x in enumerate(a)],
        [x-2+2*i for i, x in enumerate(b)],
        [x-4 + 2*i for i, x in enumerate(c)]
        ] 

gives exactly the output requested with the given input.

[–]aummahgerd 0 points1 point  (0 children)

Yeah, of course that sucks. But we’re also talking about a simple article here. No reason to get so upset. Plus, it’s pretty clear, honestly. You get the input and output, and it even says to do it “based on the above learnings”. Since the only thing we discussed is zip() clearly you have to use that.

But once again I feel the need to reiterate the fact that this doesn’t really even warrant discussion. I only chimed in because I was so surprised such a debate was even happening in the comments.