Skip to content

Tag: list

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

Custom list class slicing functionality

I want to implement my own type of list called Stack. I also want to add slicing functionality with the __getitem__ method like so: Now if I create a Stack instance and append some elements to it I get the Stack type: but if I slice my Stack, it becomes a list again: how can I make st_sliced to stay

Why do I get ‘IndexError: list index out of range’

I get this error: IndexError: list index out of range This is my function: Call my function: How can I solve this problem? Answer Ok, so now you’ve changed your code and my previous answer has been invalidated. Now your problem is here: with n+1 because n comes from for n in range(len(list)): and eventu…

validation-remove currency symbol from price

I have this one string, which is actually price, this price value comes with any currency symbol (currency_list), I am trying to remove these currency symbols from price and return only price. Till now I am able to do it for prefix and suffix currency symbol using below code , everything works till here. I ju…