python tutorial - Python interview questions google - learn python - python programming
python interview questions :161
Sort Dictionary by Value using only .Sort() ?
- So many things we take for granted in newer versions.
Learn python - python tutorial - sort-dictionary - python examples - python programs
- Anyways, Schwartzian Transform:
python interview questions :162
What is the canonical way to create network packets in Objective C?
- Using a C struct is the normal approach. For example:
- Would define a type for an int, 2 characters and a float. You can then interpret those bytes as a byte array for writing:
python interview questions :163
Find the 2nd highest element ?
- If performance is a concern (e.g.: you intend to call this a lot), then you should absolutely keep the list sorted and de-duplicated at all times, and simply the first, second, or nth element (which is o(1)).
Learn python - python tutorial - max-default - python examples - python programs
- Use the bisect module for this - it's faster than a "standard" sort.
- insert lets you insert an element, and bisect will let you find whether you should be inserting at all (to avoid duplicates).
- If it's not, I'd suggest the simpler:
- If the reverse indexing looks ugly to you, you can do:
python interview questions :164
Extract text from HTML in python ?
- The question that monkut references doesn't give any Python solution to the exact problem.
- While BeautifulSoup and lxml both can be used to parse html, there is still a big step from there to text that approximates the formatting that is embedded in the html
Learn python - python tutorial - source-code - python examples - python programs
- To do this, I have resorted to non-python solutions (which I've blogged about, but will resist linking here-- not sure of the SO etiquette).
- If you are on a *nix system, you can install this html2text package from Germany.
- It can be installed easily on a MacOS with Homebrew ($ brew install html2text) or Macports ($ sudo port install html2text), and on other *nix systems through their package managers.
It has a number of useful options, and I use it like this:
- You can also install a text-based browser (e.g. w3m) and use it to produce formatted text from html using the following command-line syntax:
w3m filename.html -dump > file.txt
- You can, of course, access these solutions from Python using the subprocess module or the popular envoy wrapper for subprocess.
- Even after all this effort, you may find that some important information (e.g. <u> tags) are not handled in a way you like, but those are the best current options that I have found
python interview questions :165
C function with pointer of points wrapping in Python?
- After some code digging I figure it out:
Learn python - python tutorial - c-function - python examples - python programs
- any C/C++ parameter that accepts a pointer to a list of values should be wrapped in python with
- and filled with
- in mycase the solution was:
python interview questions :166
Python… Static variables?
- It is declared diffrent area. Ex1 is Like global or static variable
Learn python - python tutorial - python-debugger - python examples - python programs
- Ex2 is local attribute.
python interview questions :167
What is the equivalent of PHP “==”?
- The question says it.
- Here's a little explanation.
- In PHP. "==" works like this
- While in python:
- The equivalent for python "==" in php is "==="
python interview questions :168
How to find number of rows of a huge csv file in pandas?
- I need to get a line count of a large file (hundreds of thousands of lines) in python.
Learn python - python tutorial - read-csv-python - python examples - python programs
- At the moment I do:
python interview questions :169
What is an InstrumentedList in Python?
- Yes, SQLAlchemy uses it to implement a list-like object which is aware of insertions and deletions of related objects to an object (via one-to-many and many-to-many relationships).
python interview questions :170
Scope of “library” methods ?
- I would recommend passing the locals() to the function, like so.
- If you don't want that, you can use the inspect module or sys getframe to do the same thing, as other have suggested.