Skip to content
Advertisement

Tag: list-comprehension

compare list elment to a string

I have the following list and the following string I want to check if any element in the list is in the string I tried using however it gives false seems python can’t recognize the element in the string, is there a way to check elements from list to a string if there is a match. i did it successfully

Use List Comprehension to get the top n items

I tried: but that won’t work because sort() doesn’t return the sorted list Answer .sort() sorts the list in-place list.sort() sorts the list in-place, mutating the list indices, and returns None (like all in-place operations) so you’d have to do this: Output: The difference between .sort() and sorted() in Python.

Advertisement