Nzec error using map function python for taking array input


I tried to solve the Problem.
So for taking input, I used map function Solution 1, Second time I tried with to solve without map function Solution 2 and it worked

Logic is the same for both problems (even code), the difference is with how I’m taking input.
Please Explain!


The error is not in the map part, it’s here:

 temp = [False] * m 
 for i in range(n):

As a simpler example, consider this:

a = [1]
b = a
a[0] = 0

You might expect this to print [1] but it’ll print [0]. It’s got to do with how python stores objects. Long story short, a and b both refer to the same list. Hence, when you change the list referred to by a, you change the list referred to by b. In your snippet above, there’s the same problem. If you write value[0][0]=True, value*[0] will become True for all i.

Also, you don’t really need to use map there, you can simply write arr.append(input().split()).


In Python 3, all input is converted to a string, so there is no need to use map.(1) The Python 3 input() is equivalent to the Python 2 raw_input().(2)

The str.split() string method, whenever no separator is specified, returns a list of words separated by any consecutive whitespace.(3) In this problem CLORGRID, strings are given without any whitespace. Therefore, given s = '..#',

s.split() = ['..#'].

Line 12 of your Solution 1 is arr.append(list(map(str, input().split()))).

For arr = [] and input '..#', this will result in arr = [['..#']]

To append a list of the individual characters of a string input to arr, I recommend using a list comprehension:

arr.append([c for c in input()])


I didn’t read your complete solution but I am sure that the NZEC you’re getting is just a symptom of this problem.


Thanks for the help