-
Code def longest_string(a): return max(a.split(),key=len)
Test Cases import unittest from solution import longest_string class TestLongestString(unittest.TestCase): def setUp(self) -> None: self.test_samples = (('codewars longest string code challenge', 'challenge'), ('Guido van Rossum created the Python programming language', 'programming'), ("Python was named after the TV comedy series 'Monty Python’s Flying Circus'", 'Python’s'), ('Python is an open-source object-oriented programming language.', 'object-oriented'), ('Python does not require a compiler', 'compiler'), ('Elvis Presley was born in Mississippi 1/8/1935', 'Mississippi'), ) def test_longest_string(self): for sample, expected in self.test_samples: self.assertEqual(longest_string(sample), expected) if __name__ == '__main__': unittest.main()
Output:
-
Code longest_string = lambda x: max(x.split(), key=lambda y: len(y))- def longest_string(a):
- return max(a.split(),key=len)
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}