0

This topic is basically based on concatenation (of iterable data) or another such data type as list. In order to make printable representation, built-in repr returns an array object strong text containing single quotes next to opposite quotes, then, contain some method associated with repr or the method used by a previous statement such as join for the next expression map(lambda x: repr("".join(list(' '*10))), range(12)) and then use as a parameter in the list() method, like the following example.

Could you remove the quote characters that are only located at indices in the index range [-2:] [2:]?

# example number N for range
map(lambda x: repr("".join(list(' '*10))), range(12))
>>> <map object at 0x00000240540F4640>
list(map(lambda x: repr("".join(list(' '*10))), range(12)))
["'          '", "'          '", "'          '", 
 "'          '", "'          '", "'          '",
 "'          '", "'          '", "'          '",
 "'          '", "'          '", "'          '"]

1 Answer 1

1

you can modify

map(lambda x: repr("".join(list(' '*10))), range(12))

to this

map(lambda x: repr("".join(list(' '*10)))[2:-2], range(12))

here is full code

>>> k = map(lambda x: repr("".join(list(' '*10)))[2:-2], range(12))
>>> list(k)
['        ', '        ', '        ', '        ', '        ', '        ', '        ', '        ', '        ', '        ', '        ', '        ']
Sign up to request clarification or add additional context in comments.

4 Comments

your answer indicates what i mentioned about indexing values and omitting quotes but when i try to do for example val = [' ', ' ', ' ', ' ', ' '], val[2] = '1000', and then "".join(val) using repr and map i see erroneous results, i was expecting other options apart of the index assignation
you need to check str methods they might help you
ok it's fixed, so I was incorrectly using the join method along with repr
yeah you just need to use it with __repr__ in class method or just during debuging

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.