As it is a challenge i tried, but i still don't get the expected results as in the exercice...It will work sometimes and sometimes not... I guess i'm on the right way...
x=0
while x<1: #Test on 1 loop only
l1 = ["C", "E", "M", "O", "P", "R", "T", "U"]
count=1 #because of initial list
new_input=input("Enter 'N String' ?")#Input format N:int+space+string
up=new_input.upper()#Chars to uppercase
splited_list=list(up)#String to list of char
#Index N
index=int(splited_list[0])#store index N
#Separated letters
letters=[c for c in splited_list if c.isalpha()]
for letter in letters:
if letter in l1:
if l1.index(letter)<=index:
count+=1
l1.insert(l1.index(letter),letter)
else:
l1.append(letter)
l1=sorted(l1)
if l1.index(letter)<=index:
count+=1
print(x,"count: "+str(count))
x+=1
Exercice input / output :
2 Computer / 1. 3
2 COMPUTER bat / 2. 5
3 COMPUTER / 3. 2
4 ACSL is fun / 4. 3
9 the xylophone / 5. 4
My input / output :
2 Computer / 1.3
2 COMPUTER bat / 2.5
3 COMPUTER / 3.4
4 ACSL is fun / 4.6
9 the xylophone / 5.11
I don't understand as i think my counts are good.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…