2014-01-10 86 views
0

錯誤:builtins.UnicodeDecodeError:「UTF-8」編解碼器不能在448位解碼字節0xa1:無效的起始字節快速排序算法的UnicodeDecodeError

def quicksort(Info): 
     lesser=[] 
     greater=[] 
     if len(Info) <= 1: 
       return Info 
     for swap in Info[1:]: 
       if swap < Info[0]: 
         lesser.append(swap) 
       else: 
         greater.append(swap) 
     print(quicksort(lesser)+Info[0:1]+quicksort(greater)) 

a= ['Babado Novo: Ver-te Mar', 'Natas es Satan', 'All Out War', '"The Cell"', '¡Ja me maaten...!', '"Formula 1: BBC Sport"', 'Ambos mundos', 'Angels with Dirty Faces', 'Barrio Gangsters', 'The LXD: The Secrets of the Ra', '90 Jahre Burgenland', 'La guitarra muda', 'Alma gitana', 'Depravada', 'Especial humor: Vaya... y vuelta', 'Entre las patas de los caballos', 'Fillet of Soul', 'Llamada', 'All of Her', "Hustler's Untrue Hollywood Stories: Angelina vs. Jennifer", 'Black Tranny Whackers 12', '"Davno ne videlis"', 'Anna II', '"The American Experience"', 'Meus Prêmios Nick 2012', 'Possessed', 'Holzapfel weiß alles', 'Lightspeed University: Cheerleader Power', 'Kid Millions', 'Monster High', '"Big Brother\'s Bit on the Side"', '"Britain\'s Got Talent"', "Heut' kommt's drauf an", "Buffalo Jill's on DVD 2004: Swimsuit Edition", '"Sigue, sigue Plàstic"', '"Move Like Michael Jackson"'] 

quicksort(a) 
+0

這將是很好有更多一點的上下文來幫助你。另外,你似乎在某些字符串中有「不尋常」的字符,你可能需要查看一下這些字符,並在python – bvidal

+0

上進行一些編碼/編碼的研究。聽起來很像這個問題,完全在'a = [ ......線,與你的快速排序實現無關。 – delnan

+0

[這可以幫助你爲什麼](http://farmdev.com/talks/unicode/) – mojibuntu

回答

1

第一,加#coding=utf8到腳本文件的頂部,

秒,將你的文件保存爲utf-8,默認情況下它可能是ANSI。

然後我收到錯誤運行代碼:

['"Big Brother\'s Bit on the Side"', '"Britain\'s Got Talent"'] 
Traceback (most recent call last): 
    File "D:\Documents\Desktop\a.py", line 23, in <module> 
    quicksort(a) 
    File "D:\Documents\Desktop\a.py", line 19, in quicksort 
    print(quicksort(lesser)+Info[0:1]+quicksort(greater)) 
    File "D:\Documents\Desktop\a.py", line 19, in quicksort 
    print(quicksort(lesser)+Info[0:1]+quicksort(greater)) 
    File "D:\Documents\Desktop\a.py", line 19, in quicksort 
    print(quicksort(lesser)+Info[0:1]+quicksort(greater)) 
    File "D:\Documents\Desktop\a.py", line 19, in quicksort 
    print(quicksort(lesser)+Info[0:1]+quicksort(greater)) 
    File "D:\Documents\Desktop\a.py", line 19, in quicksort 
    print(quicksort(lesser)+Info[0:1]+quicksort(greater)) 
TypeError: unsupported operand type(s) for +: 'NoneType' and 'list'