Skip to content
Advertisement

Tag: python

How do I concatenate two lists in Python?

This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions. How do I concatenate two lists in Python? Example: Expected outcome: Answer Use the + operator to combine the lists: Output:

Check if object is file-like in Python

File-like objects are objects in Python that behave like a real file, e.g. have a read() and a write method(), but have a different implementation from file. It is realization of the Duck Typing …

Including non-Python files with setup.py

How do I make setup.py include a file that isn’t part of the code? (Specifically, it’s a license file, but it could be any other thing.) I want to be able to control the location of the file. In the original source folder, the file is in the root of the package. (i.e. on the same level as the topmost

Check if a given key already exists in a dictionary

This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions. I wanted to test if a key exists in a dictionary before updating the value for the key. I wrote the following code: I think this is not the best way to accomplish this task. Is there

User-friendly time format in Python?

Python: I need to show file modification times in the “1 day ago”, “two hours ago”, format. Is there something ready to do that? It should be in English. Answer The code was originally published on a blog post “Python Pretty Date function” (http://evaisse.com/post/93417709/python-pretty-date-function) It is reproduced here as the blog account has been suspended and the page is no

Advertisement