Skip to content

Tag: python

All combinations of a list of lists [duplicate]

This question already has answers here: How to get the cartesian product of multiple lists (17 answers) Closed 8 months ago. I’m basically looking for a python version of Combination of List<List<int>> Given a list of lists, I need a new list that gives all the possible combinations of items…

Python “protected” attributes

How do I access a private attribute of a parent class from a subclass (without making it public)? Answer My understanding of Python convention is _member is protected __member is private Options for if you control the parent class Make it protected instead of private since that seems like what you really want…

How to truncate float values?

I want to remove digits from a float to have a fixed number of digits after the dot, like: I need to output as a string to another function, not print. Also I want to ignore the lost digits, not round them. Answer First, the function, for those who just want some copy-and-paste code: This is valid in Python 2…

Python difflib: highlighting differences inline?

When comparing similar lines, I want to highlight the differences on the same line: While difflib.HtmlDiff appears to do this sort of inline highlighting, it produces very verbose markup. Unfortunately, I have not been able to find another class/method which does not operate on a line-by-line basis. Am I miss…

Python : How to convert markdown formatted text to text

I need to convert markdown text to plain text format to display summary in my website. I want the code in python. Answer The Markdown and BeautifulSoup (now called beautifulsoup4) modules will help do what you describe. Once you have converted the markdown to HTML, you can use a HTML parser to strip out the p…

Securely Erasing Password in Memory (Python)

How do you store a password entered by the user in memory and erase it securely after it is no longer need? To elaborate, currently we have the following code: After calling the login method, what do we need to do to fill the area of memory that contains password with garbled characters so that someone cannot…

Find Hyperlinks in Text using Python (twitter related)

How can I parse text and find all instances of hyperlinks with a string? The hyperlink will not be in the html format of <a href=”http://test.com”>test</a> but just http://test.com Secondly, I would like to then convert the original string and replace all instances of hyperlinks into c…