Skip to content

Tag: python

Splitting long string without spaces into words with certain length

So I have a really long string from a text document made entirely up of 7-letter words. I need to separate them and store each 7-letter word into an list. The text document is originally made up of 7-letter words each separated by lines. A small part of it is shown below: Screenshot of the text document After…

elif: SyntaxError: invalid syntax

I want to re.search within an if statement but regardless of identation, get syntax error. Is it because elif: has no condition? error message Answer In elif you have if, it requires a condition and you provide none, it should be Using walrus operator (since py3.8) you can improve your code to look like If th…

How To give optional parameter in DRF

Hi Everyone i am created one api, where i will use [city] as first parameter to get result based on city, but i need [id] also as second parameter but [id] is optional, same time we use [id] as second parameter and sometime not, please help me out for ex- 1-get data based on city url=127.0.0.1:8000/api/car/ci…