python string operation using for loop to print diffrerent words in list of same word

Viewed 31

I want to print a list of a input string where the list contains different words from the same string, in every word in that list I want to print the last letter in place of the first letter.The other letters get shifted from their position forward. For example: hello
The list contains words like
hello=['ohell', 'lohel', 'llohe', 'elloh', 'hello']

my code is:

a = []
s = input("Enter the string")
n = len(s)
def list1(s):
    print(n)
    for i in s:    
        #Hello=["ohell", "lohel", "llohe", "elloh", "hello"]
        a.append(s)
        
list1(s)
print(a)
1 Answers

You could use string indexing:

s = "hello"
print([s[i:] + s[:i] for i in range(len(s))])
# ['hello', 'elloh', 'llohe', 'lohel', 'ohell']
Related