+ 11

[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

22nd Oct 2020, 5:42 PM
C K
C K - avatar
20 odpowiedzi
+ 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
22nd Oct 2020, 6:03 PM
Alexander Thiem
Alexander Thiem - avatar
+ 6
Frogged something like that. not necessarily equal.
22nd Oct 2020, 5:54 PM
C K
C K - avatar
+ 6
Alexander Thiem Thanks 👌now it works.
22nd Oct 2020, 6:23 PM
C K
C K - avatar
+ 4
Frogged already did don't you see that?
22nd Oct 2020, 7:01 PM
C K
C K - avatar
+ 4
C K This is my question😂 Thanks😊
23rd Oct 2020, 1:21 PM
Սոֆի
+ 3
Alexander Thiem I don't really understand what you are saying.
22nd Oct 2020, 5:57 PM
C K
C K - avatar
+ 3
Jayakrishna🇮🇳 which separator should I use, cause it's just a word not a sentence.
22nd Oct 2020, 6:04 PM
C K
C K - avatar
+ 3
22nd Oct 2020, 6:08 PM
C K
C K - avatar
+ 3
Alexander Thiem only works for numbers divisible by the words length doesn't work for 7 or 5 even 2 outputs. so lo only.
22nd Oct 2020, 6:10 PM
C K
C K - avatar
+ 3
C K Of course, my fault... in the list lengthOfNewWords(l) has to be used and not n... now it works
22nd Oct 2020, 6:14 PM
Alexander Thiem
Alexander Thiem - avatar
+ 3
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)
23rd Oct 2020, 4:05 AM
C K
C K - avatar
0
W = sololearn N = 3 s o lolearn
22nd Oct 2020, 5:53 PM
Oma Falk
Oma Falk - avatar
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)
22nd Oct 2020, 5:57 PM
Jayakrishna 🇮🇳
0
wlcm
22nd Oct 2020, 6:08 PM
Alexander Thiem
Alexander Thiem - avatar
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)
22nd Oct 2020, 6:24 PM
Alexander Thiem
Alexander Thiem - avatar
0
Alexander Thiem you are right. Your answer deserves to ne marked as best.C K it ks up to you.
22nd Oct 2020, 6:57 PM
Oma Falk
Oma Falk - avatar
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
22nd Oct 2020, 7:00 PM
Alexander Thiem
Alexander Thiem - avatar
0
wow I can't believe
23rd Oct 2020, 3:34 AM
Jr Danish
Jr Danish - avatar
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)
23rd Oct 2020, 12:22 PM
Jayakrishna 🇮🇳
0
Real?
24th Oct 2020, 9:50 AM
Kim Guk John
Kim Guk John - avatar