+ 37

[ ASSIGNMENT: ] Word Values

Given a String "abc" and assuming that each letter in the String has a value equal to its position in the alphabet ("abc" has a value of 6) This means that a=1, b=2, c=3 ... z=26 TASK : Given a list of strings. Return the values of the strings multiplied by the position of that String in the list. Position begins with 1 Example :: nameValue ["abc", "abc abc"] return [6, 24]  because of [ 6*1, 12*2 ]. Spaces are ignored! NOTE : Input will only contain lowercase characters and spaces! HappyCodings!:-)

9th May 2018, 7:13 PM
Danijel Ivanović
Danijel Ivanović - avatar
23 Answers
9th May 2018, 10:38 PM
LukArToDo
LukArToDo - avatar
11th May 2018, 5:46 PM
🌛DT🌜
🌛DT🌜 - avatar
10th May 2018, 8:51 AM
Uni
Uni - avatar
+ 17
Hello, 🤗 Flash do you want my answers (are they so interesting! 😆) or you want to solve the tasks and show the way and solution from which something new can be learned👍 No, you will not find my solution 😄🤘 I'm glad you're participating and writing java one-liners 👍😉🍻
6th Jul 2018, 7:12 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 15
Morpheus 💪Indeed my friend! 😄😀👏👏
14th May 2018, 7:32 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 15
Flash why to hide them when you are so interested, 😁😉👌 I am really honored, 👏🍻 thank you very much for your interest! 👍😊
6th Jul 2018, 7:42 PM
Danijel Ivanović
Danijel Ivanović - avatar
9th May 2018, 8:06 PM
Zoetic_Zeel
Zoetic_Zeel - avatar
+ 11
https://code.sololearn.com/c86oWngLwDMa/?ref=app
10th May 2018, 7:34 AM
Paul
Paul - avatar
9th Jul 2018, 12:48 AM
Martin Möhle
Martin Möhle - avatar
+ 10
v=lambda l:sum(n*(sum(map(ord,s))-96*len(s)) for n,s in enumerate(" "+l))
10th May 2018, 1:01 PM
VcC
VcC - avatar
9th May 2018, 11:38 PM
cyk
cyk - avatar
14th May 2018, 3:33 AM
Nevfy
11th May 2018, 5:50 PM
Karan Zala
+ 5
Nevfy Pb too simple to spend much time refining it:-) Btw your one liner could be shorter ([(i+1)*sum((ord(c)-96)*c.isalpha() for c in s) for i,s in enumerate(input().split(','))])
14th May 2018, 5:49 AM
VcC
VcC - avatar
+ 5
JavaScript was missing here's an attempt https://code.sololearn.com/WPH8JOZH9prF/?ref=app
14th May 2018, 4:34 PM
Morpheus
Morpheus - avatar
+ 3
@~ swim ~ Yes, sure, they are often not easy to read. In real life I never use more than 2 or 3 operations per line and have them commented for any further users of my code, but these solutions are made for fun, so we can play around and demonstrate a real power of Python even if it makes a code hardly readable. And possibility to read them is a skill, which comes with practice and based on good knowledge of the language and your own experience as well.
14th May 2018, 1:55 PM
Nevfy
+ 3
Danijel Ivanović hi, i could’t find ur solution. btw, python is not the only lang that allows one-liners ;) ,so my tries: c# one-liner https://code.sololearn.com/ci91XZj4hJ4b/?ref=app java one-liner https://code.sololearn.com/cd8VdfC0t8OQ/?ref=app
6th Jul 2018, 6:27 PM
Flash
+ 3
~ swim ~ so, u fould the key to this ;) btw, it’s a valid c++ one-liner. well done!
6th Jul 2018, 7:44 PM
Flash
+ 2
@VcC One line - three bugs :-) 1. Positions start from 1 not from 0. Your solution will always return 0 for first string in a list. 2. Doesn't work correctly with spaces. 3. A list of sums is required as an output, not a total sum.
14th May 2018, 3:43 AM
Nevfy
+ 2
@VcC Nice idea, I think I saw already such approach in one of your oneliners. I shell try to remember it to use it next time. Thanks :-)
14th May 2018, 9:41 AM
Nevfy