Extract first item of each sublist in Python
Using list comprehension: >>> lst = [[‘a’,’b’,’c’], [1,2,3], [‘x’,’y’,’z’]] >>> lst2 = [item[0] for item in lst] >>> lst2 [‘a’, 1, ‘x’]
Using list comprehension: >>> lst = [[‘a’,’b’,’c’], [1,2,3], [‘x’,’y’,’z’]] >>> lst2 = [item[0] for item in lst] >>> lst2 [‘a’, 1, ‘x’]
If you only need the dictionary keys 1, 2, and 3 use: your_dict.keys(). If you only need the dictionary values -0.3246, -0.9185, and -3985 use: your_dict.values(). If you want both keys and values use: your_dict.items() which returns a list of tuples [(key1, value1), (key2, value2), …].
I find that it is only bad practice in that it can lead to a number of variables which future maintainers (or yourself in a few weeks) have no idea where they’re coming from. Consider this scenario: extract($someArray); // could be $_POST or anything /* snip a dozen or more lines */ echo $someVariable; Where … Read more
Option 1. First you map the array to get those numbers (and not the full details): $numbers = array_column($array, ‘weight’) Then you get the min and max: $min = min($numbers); $max = max($numbers); Option 2. (Only if you don’t have PHP 5.5 or better) The same as option 1, but to pluck the values, use … Read more
A faster and easier-to-understand filter that accomplishes the same thing: git filter-branch –index-filter ‘ git read-tree –empty git reset $GIT_COMMIT — $your $files $here ‘ \ — –all — $your $files $here
No need for external plugins. In the Export JAR dialog, make sure you select all the necessary resources you want to export. By default, there should be no problem exporting other resource files as well (pictures, configuration files, etc…), see screenshot below.
If you want the pure plain text(my requirement) then all you need is unzip -p some.docx word/document.xml | sed -e ‘s/<[^>]\{1,\}>//g; s/[^[:print:]]\{1,\}//g’ Which I found at command line fu It unzips the docx file and gets the actual document then strips all the xml tags. Obviously all formatting is lost.
Create an element, store the HTML in it, and get its textContent: function extractContent(s) { var span = document.createElement(‘span’); span.innerHTML = s; return span.textContent || span.innerText; }; alert(extractContent(“<p>Hello</p><a href=”http://w3c.org”>W3C</a>”)); Here’s a version that allows you to have spaces between nodes, although you’d probably want that for block-level elements only: function extractContent(s, space) { var span= … Read more
For InstallShield MSI based projects I have found the following to work: setup.exe /s /x /b”C:\FolderInWhichMSIWillBeExtracted” /v”/qn” This command will lead to an extracted MSI in a directory you can freely specify and a silently failed uninstall of the product. The command line basically tells the setup.exe to attempt to uninstall the product (/x) and … Read more
Here’s a great python module someone wrote to solve this problem after seeing this question: https://github.com/john-kurkowski/tldextract The module looks up TLDs in the Public Suffix List, mantained by Mozilla volunteers Quote: tldextract on the other hand knows what all gTLDs [Generic Top-Level Domains] and ccTLDs [Country Code Top-Level Domains] look like by looking up the … Read more