+ 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!:-)
31 Respuestas
+ 25
+ 18
If I have the time and if I'll manage to I'll try to do it in other programming languages but for now here's my try:
https://code.sololearn.com/cQKY4dHkNmDg/?ref=app
https://code.sololearn.com/cQl95DyHrY7K/?ref=app
https://code.sololearn.com/c1q7WqAY896t/?ref=app
https://code.sololearn.com/cCqETuovXzJ3/?ref=app
+ 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 👍😉🍻
+ 15
Morpheus 💪Indeed my friend! 😄😀👏👏
+ 15
Flash why to hide them when you are so interested, 😁😉👌
I am really honored, 👏🍻
thank you very much for your interest! 👍😊
+ 11
https://code.sololearn.com/c86oWngLwDMa/?ref=app
+ 10
v=lambda l:sum(n*(sum(map(ord,s))-96*len(s)) for n,s in enumerate(" "+l))
+ 9
My implementation in Java
https://code.sololearn.com/cddFdxU13YQ2/?ref=app
+ 6
Python oneliner is here:
https://code.sololearn.com/cq7m1O0jsXy7/?ref=app
+ 5
See this code👇
https://code.sololearn.com/ce6IJqobKrRW/?ref=app
+ 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(','))])
+ 5
JavaScript was missing here's an attempt
https://code.sololearn.com/WPH8JOZH9prF/?ref=app
+ 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.
+ 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
+ 3
~ swim ~ so, u fould the key to this ;) btw, it’s a valid c++ one-liner. well done!
+ 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.
+ 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 :-)