+ 7

What is the mistake in this code?

https://code.sololearn.com/cokV30bOdTh2/?ref=app In python core project all test cases failed...

24th Oct 2022, 11:04 AM
Riya
Riya - avatar
16 Antworten
+ 1
# Instead of that confusing ways , you can try these simple ways : a = input().split() # split input b=[] for i in a : b.append(len(i)) # add length of each print(a[ b.index(max(b)) ]) # index value of max in b is index of max length value of a. #other way maxi = "" for i in a : if len(i)>len(maxi) : maxi = i print(maxi)
24th Oct 2022, 11:41 AM
Jayakrishna 🇮🇳
+ 11
Riya , you are using : print(a[b.index(max(b))]) wich looks not quite straight forward. we can use max() directly without using index(). max() function has a key argment, that we can use to define what sortingkey we wanted to use. in our case it is the length of each element in the list lst = input().split() print(max(lst, key = len))
24th Oct 2022, 3:45 PM
Lothar
Lothar - avatar
+ 6
Sidney Masilela , please do not place a new question inside an exising and running post. take your code and use a new post. give a clear description what your problem is.
24th Oct 2022, 8:14 PM
Lothar
Lothar - avatar
+ 6
محمدرضا ایجادی what do you mean by your post? it has no real relation to the question of this thread, but could be seen as spam.
26th Oct 2022, 11:46 AM
Lothar
Lothar - avatar
+ 4
Jayakrishna🇮🇳 yeah max prints lexicographical order... thank you..I understand
24th Oct 2022, 11:31 AM
Riya
Riya - avatar
+ 4
Jayakrishna🇮🇳 thank you now I got it in first code..you take the length and append it and printing the index..it is the logic right
24th Oct 2022, 11:44 AM
Riya
Riya - avatar
+ 4
Lothar thank you..it looks more compact..
24th Oct 2022, 4:44 PM
Riya
Riya - avatar
+ 3
Jayakrishna🇮🇳 I have to find the longest word from the sentence
24th Oct 2022, 11:18 AM
Riya
Riya - avatar
+ 2
What is the task there?
24th Oct 2022, 11:17 AM
Jayakrishna 🇮🇳
+ 2
max( b) returns Maximum value string lexiograhically.. ex: ab abc abcd azz output : azz instead of abcd
24th Oct 2022, 11:25 AM
Jayakrishna 🇮🇳
+ 2
Mohd Aadil it's working now... thank you.. what is the logic you used.. can you explain?
24th Oct 2022, 11:29 AM
Riya
Riya - avatar
+ 2
This is the very nice 👍
24th Oct 2022, 5:01 PM
Vishal Sharma
+ 2
Samir Hassanzadeh , please do not place a new question inside an exising and running post. take your code and use a new post. give a clear description what your problem is.
25th Oct 2022, 4:57 PM
Lothar
Lothar - avatar
+ 1
It's working now 😁 txt = input() a=txt.split(' ') b=[''] for i in a: leni = len(i) if(len(b[-1]) < leni): b = [] b.append(i) print(*b) #iam learning python---->input #output--->learning
24th Oct 2022, 11:24 AM
Mohd Aadil
Mohd Aadil - avatar
0
Can someone please help me. I don't know what to do next function main() { var depth = parseInt(readLine(), 10); var i = depth var x= 1 var y=4 do { i=(i-5); x++} while (i>27); console.log(y+x); }
24th Oct 2022, 5:35 PM
Sidney Masilela
Sidney Masilela - avatar
0
mohsah=[] x=input("x:") y=input("y:") z=input("z:") mohsah.append('x') mohsah.append('y') mohsah.append('z') print(mohsah) Doy you know whats the problem
25th Oct 2022, 2:30 PM
Samir Hassanzadeh
Samir Hassanzadeh - avatar