#Pyth, 17
Pyth, 17
#Pyth, 17
Pyth, 17
[Try it here.][1]
Explanation to follow. [1]: http://pyth.herokuappTry it here.com/
Explanation:
Implicit:
z = input() z is the string.
Q = eval(input()) Q is the length.
< Q First Q characters of
u UQ*zQ Reduce, with an initial value of z repeated Q times,
on the list range(len(Q)).
Since the reduce function doesn't use the sequence variable H
this function amounts to applying the inner code Q times to
the initial value, where the working variable is G.
ss Sum from list of tuples of strings, to tuple of strings,
to string.
C, Zip together
cG\_ G split on underscores
G with G.
This inserts a character of G between every underscore
separated group of G, which amounts to replacing the
underscores with characters of G, after summation.
[Try it here.][1]
Explanation to follow. [1]: http://pyth.herokuapp.com/
Explanation:
Implicit:
z = input() z is the string.
Q = eval(input()) Q is the length.
< Q First Q characters of
u UQ*zQ Reduce, with an initial value of z repeated Q times,
on the list range(len(Q)).
Since the reduce function doesn't use the sequence variable H
this function amounts to applying the inner code Q times to
the initial value, where the working variable is G.
ss Sum from list of tuples of strings, to tuple of strings,
to string.
C, Zip together
cG\_ G split on underscores
G with G.
This inserts a character of G between every underscore
separated group of G, which amounts to replacing the
underscores with characters of G, after summation.
#Pyth, 17
<ussC,cG\_GUQ*zQQ
Input should be given with the string on the first line, and the length on the second, on STDIN. For example:
abc____
50
[Try it here.][1]
Explanation to follow. [1]: http://pyth.herokuapp.com/