Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- myList = ["This", "is", "a", "great", "list"]
- n = 2
- tempN = n
- res = []
- for i in range(len(myList)-n+1):
- start, tempRes = myList[i], ""
- for j in range(i, len(myList)):
- if tempN>0:
- if tempN == 1:
- tempRes += f"{myList[j]}"
- else:
- tempRes += f"{myList[j]} "
- tempN -= 1
- else:
- res.append(tempRes)
- tempN = n
- print(res)
- ##Output : ['This is', 'is a', 'a great', 'great list']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement