Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability. Use the python tag for all Python related questions. If you believe your question may be even more specific, you can include a version specific tag such as python-3.x.
5
votes
3
answers
662
views
Add element alternatively to a list
I want to place an element alternatively between any two elements of a list.
l1 = list('abcde')
fill = 'z'
How it should look like:
['a', 'z', 'b', 'z', 'c', 'z', 'd', 'z', 'e']
My solution:
fi …
2
votes
1
answer
2k
views
Populate a networkx graph with tuples of varying lengths
I've got a list with tuples of variable length containing nodes, out of which I want to build a network:
node_list = [("one", "two"), ("eins", "zwei", "drei"),
("un", "deux", "trois", "q …
2
votes
1
answer
427
views
Save list over many csv files each with given number of lines
I wrote a little code for outputting to csv. It takes a list object named outtext and saves multiple .csv files. Each csv file contains cutoff elements of the list (except for the last), where cutoff …
2
votes
1
answer
7k
views
Check existence of HTML tags in a row
Using Python's Beautiful Soup, I analyze a number of html files (internally: soup). They are all a little different and my target comes in four different tags - or not at all. In two cases, my target …
1
vote
1
answer
2k
views
Reading two csv files as dictionaries with differing key definitions
My script reads two .csv files and generates one dictionary per .csv file.
import csv
# First dictionary
first_dict = {}
with open(first_file, 'r') as f:
csvReader = csv.reader(f)
next(csvRea …
3
votes
1
answer
3k
views
Rename subkeys of nested dictionary dynamically
My nested (ordered) dictionary looks like this:
OrderedDict([
('1', OrderedDict([('1994_fte_count', '4'), ('1995_fte_count', '2'), ('1996_fte_count', '5'), ('1997_fte_count', '7')])),
('2', O …
0
votes
Remove (not extract) timestamp from HTML string
Based on MathiasEttinger's suggestions in the comments and my initial feeling, I tried using dateutils:
from bs4 import BeautifulSoup
from dateutil import parser
date1 = '<P><SPAN STYLE="font-family …
1
vote
2
answers
1k
views
Remove (not extract) timestamp from HTML string
I've got strings coming from irregularly and ugly formatted HTML sites, that contain a timestamp. I am interested in removing the timestamp entirely and get all the rest.
from bs4 import BeautifulSou …
6
votes
2
answers
3k
views
Compute spherical distance matrix from list of geographical coordinates
I've got a list of geographic coordinates ([lat, long]) and want to compute the corresponding matrix of distances. Distance shall be spherical distance in km.
def distance_on_unit_sphere(coord1, coor …