
Weekly Challenge: The one liners
Weekly Challenge 362 Each week Mohammad S. Anwar sends out The Weekly Challenge , a chance for all of us to come up with solutions to two weekly tasks. My solutions are written in Python first, and then converted to Perl. Unless otherwise stated, CoPilot (and other AI tools) have NOT been used to generate the solution. It's a great way for us all to practice some coding. Challenge , My solutions Task 1: Echo Chamber Task You are given a string containing lowercase letters. Write a script to transform the string based on the index position of each character (starting from 0 ). For each character at position i , repeat it i + 1 times. My solution Both of this weeks solutions are a one-liner in Python. For this task, the function is def echo_chamber ( input_string : str ) -> str : return '' . join ( letter * pos for pos , letter in enumerate ( input_string , start = 1 ) ) Multiplying a string ( letter ) by an integer ( pos ) will repeat the string the specified number of times. The enumer
Continue reading on Dev.to Python
Opens in a new tab



