0
\$\begingroup\$

This question already has an answer here:

Write a program which removes any common leading spaces from the input string. For example, if the least indented line started with 3 spaces, and every other line has >= 3 leading spaces, then remove 3 spaces from the beginning of each line.

The indentation consists solely of spaces, and the string will not contain any tabulation. This is the same as the textwrap.dedent function in python.

Example (input, output):

Input

       7aeiou
   3b
     555

Output

    7aeiou
3b
  555

Input

this
 is
  a
   test

Output

this
 is
  a
   test

Input

    Hello 
 world

Output

   Hello 
world
\$\endgroup\$

marked as duplicate by DJMcMayhem code-golf Jan 3 at 22:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    \$\begingroup\$ Hi! I'm not familiar with Python. Can you explain what the dedent function does, so we can replicate it without needing to know Python? Thanks! \$\endgroup\$ – AdmBorkBork Jan 3 at 21:24
  • 1
    \$\begingroup\$ please don't override PPCG's default submission guidelines. It's usually perfectly fine to submit functions without calling them, and allowing input as a predefined variable just turns submissions into snippets \$\endgroup\$ – Jo King Jan 3 at 21:25
  • 3
    \$\begingroup\$ Additionally, this looks very close to being a duplicate of codegolf.stackexchange.com/q/53219/42963 \$\endgroup\$ – AdmBorkBork Jan 3 at 21:26
  • \$\begingroup\$ It seems that example text looses 3 leading spaces on each line? Is this what the task is? May we assume that input always has at least 3 spaces on each line? May we assume a variable to hold a list of strings if this is more natural to our language? \$\endgroup\$ – Adám Jan 3 at 21:27
  • \$\begingroup\$ @DJMcMayhem, thanks, I didn't know what the minimum proper question could be. \$\endgroup\$ – Mathieu CAROFF Jan 3 at 22:22
0
\$\begingroup\$

Perl 6, 11 bytes

*.indent(*)

Try it online!

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.