+ 7
What is the mistake in this code?
https://code.sololearn.com/cokV30bOdTh2/?ref=app In python core project all test cases failed...
16 Réponses
+ 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)
+ 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))
+ 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.
+ 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.
+ 4
Jayakrishna🇮🇳 yeah max prints lexicographical order... thank you..I understand
+ 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
+ 4
Lothar thank you..it looks more compact..
+ 3
Jayakrishna🇮🇳 I have to find the longest word from the sentence
+ 2
What is the task there?
+ 2
max( b) returns Maximum value string lexiograhically..
ex:
ab abc abcd azz
output : azz instead of abcd
+ 2
Mohd Aadil it's working now... thank you.. what is the logic you used.. can you explain?
+ 2
This is the very nice 👍
+ 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.
+ 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
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);
}
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