>>> help(map)
Help on class map in module builtins:
class map(object)
| map(func, *iterables) --> map object
|
| Make an iterator that computes the function using arguments from
| each of the iterables. Stops when the shortest iterable is exhausted.
here in map( lambda x: x + 1, range(5))[2:3]
,
map( lambda x: x + 1, range(5))
will create an iteratable object, on which you can iteratre (with loop or iter func). you cannot do list slicing on this part [2:3]
.
to do list slicing, you need to first iterate over this iterable and then save it into list/tuple and then do slicing.
so since you are, directly using list slicing on this, you are facing this error TypeError: 'map' object is not subscriptable
so solution will be first store data in list/tuple by iterating over the map object and then doing slicing
# using list
list(map( lambda x: x + 1, range(5)))[2:3]
# using tuple
tuple(map( lambda x: x + 1, range(5)))[2:3]