 [SOLVED]How to split a word a n times given n as an integer and n is less than the length of the word. | SoloLearn: Learn to code for FREE!

+10

# [SOLVED]How to split a word a n times given n as an integer and n is less than the length of the word.

This question got me thinking https://www.sololearn.com/discuss/2556977/?ref=app

+9

C K length of new parts(l)=length of whole word/n Then you take first l letter and next.... somehow trivial https://code.sololearn.com/cLCfXrEjHZks/?ref=app

+5

Frogged something like that. not necessarily equal.

+5

Alexander Thiem Thanks 👌now it works.

+4

C K This is my question😂 Thanks😊

+3

C K Of course, my fault... in the list lengthOfNewWords(l) has to be used and not n... now it works

+3

Frogged already did don't you see that?

+2

Alexander Thiem I don't really understand what you are saying.

+2

Jayakrishna🇮🇳 which separator should I use, cause it's just a word not a sentence.

+2

Thanks Alexander Thiem

+2

Alexander Thiem only works for numbers divisible by the words length doesn't work for 7 or 5 even 2 outputs. so lo only.

+2

Jayakrishna🇮🇳 your code gives six parts of the string not five. Maybe use n-1. s="Sololearn" n=5 ss = list(s[:n-1]) ss.append((s[n-1:])) print(ss)

0

W = sololearn N = 3 s o lolearn

0

Put the second argument of split as needed maximum splits.. Edit : Then for single word, my try : C K s="Sololearn" n=5 ss = list(s[:n]) ss.append((s[n:])) print(ss)

0

welcome! If I were you I would mark the answer as best, where I posted the code and not the other one.... Ohh and if your query was solved, why not marking this question as solved (editing the question)

0

Alexander Thiem you are right. Your answer deserves to ne marked as best.C K it ks up to you.

0

Frogged He already did, just my wrong answer (where I told, it works now..) Now he has changed on my right answer...., so everything as I would suggest

0

0

C K That's an example only.. You can redefine as you need.. Take n = int(input()) %len(s)# now you can give value of needed parts. Yes. Index start from 0 so if need 5 parts input 5-1=4 like wise... Yes.. Yours Edit works i think.. Edit : s="Sololearn" n=int(input())%len(s) ss = list(s[:n]) ss.append((s[n:])) print(ss)