python at deborahswanson.net
Wed Dec 21 19:55:18 EST 2016
I'm not a beginning python coder, but I'm not an advanced one either. I
can't see why I have this problem, though at this point I've probably
been looking at it too hard and for too long (several days), so maybe
I'm just too close to it.
Can one of you guys see the problem (besides my childish coding)? I'll
give you the code first, and then the problem.
ls = 
with open('E:\\Coding projects\\Pycharm\\Moving\\New Listings.csv',
'r') as infile:
raw = csv.reader(infile)
indata = list(raw)
rows = indata.__len__()
for i in range(rows):
# sort: Description only, to make hyperelinks & find duplicates
# find & mark dups, make hyperlink if not dup
for i in range(1, len(ls) - 1):
if ls[i] == ls[i + 1]:
ls[i] = "dup"
# make hyperlink
desc = ls[i]
url = ls[i]
ls[i] = '=HYPERLINK(\"' + url + '\",\"' + desc + '\")'
# save to csv
with open('E:\\Coding projects\\Pycharm\\Moving\\Moving 2017
out.csv', 'w') as outfile:
writer = csv.writer(outfile, lineterminator='\n')
def mergeSort(L, compare = operator.lt):
if len(L) < 2:
middle = int(len(L)/2)
left = mergeSort(L[:middle], compare)
right = mergeSort(L[middle:], compare)
return merge(left, right, compare)
def merge(left, right, compare):
result = 
i,j = 0, 0
while i < len(left) and j < len(right):
if compare(left[i], right[j]):
i += 1
j += 1
while (i < len(left)):
i += 1
while (j < len(right)):
j += 1
The problem is that while mergeSort puts the list ls in perfect order,
which I can see by looking at result on merge's final return to
mergeSort, and at the left and the right once back in mergeSort. Both
the left half and the right half are in order. But the list L is still
in its original order, and after mergeSort completes, ls is still in its
original order. Maybe there's some bonehead error causing this, but I
just can't see it.
I can provide a sample csv file for input, if you want to execute this,
but to keep things simple, you can see the problem in just a table with
webpage titles in one column and their urls in the second column.
Any insights would be greatly appreciated.
More information about the Python-list