Coders Packet

Word Stretch using Python

By Noolu Samyuktha

In this module, we are going to write python code for getting all possibilities for stretching a word to the given size.

In this module, we are going to write a program to stretch a word by considering the string, size of the word, and also the indices.

So, the main goal of the program is to get all possibilities (in sorted order) for stretching a word to the given size. If the list of required indices is passed, then only those combinations present at those indices should be returned. If the required indices are null, then all the combinations have to be returned.

Examples :

Splitting the program into 2 cases to make it more clear by considering the inputs we get:

Case 1:

If the list of required indices is passed, then only those combinations present at those indices should be returned.

example 1

The above string “1234”, with stretch length can be stretched for different possibilities like "111234", "112334", "112344" etc.
The output represents a list of different stretches in a sorted manner. Since the indices are given as null we print the entire list of possibilities

Case 2:

If the required indices are null, then all the combinations have to be returned.

example 2

Here only stretched strings of given indices are printed.

This can also be computed using words or strings, attaching output screenshots of few examples:

since here the string is "merit" and the size of the word is "6" and the indices are null. So, the output will be the word stretch of a given string with length 6 with indices zero. Hence all the possible word stretches are given as an output.

since here the string is "java" and the size of the word is "4" (which is not greater than string) and the indices are null. So, the output will be the same as the string. 

Download project

Reviews Report

Submitted by Noolu Samyuktha (samyukthanoolu)

Download packets of source code on Coders Packet