非 ASCII 文字の選択的削除
テキスト データを操作する場合、多くの場合、特定の記号を保持しながら非 ASCII 文字を削除する必要があります。スペースやピリオドなど。基本的なフィルタリング方法ではすべての非 ASCII 文字を削除できますが、場合によってはこれが望ましくない可能性があります。
次のコードを考えてみましょう:
<code class="python">def onlyascii(char): if ord(char) 127: return '' else: return char</code>
このコードは、ASCII 値を持つすべての文字を削除します。 48 未満または 127 を超え、非 ASCII 文字のテキストが効果的に削除されます。ただし、スペース (ASCII 32) とピリオド (ASCII 46) も削除されます。
スペースとピリオドを保持しながら非 ASCII 文字を選択的に削除するには、Python の string.printable モジュールを利用できます。
<code class="python">import string printable = set(string.printable) filtered_data = filter(lambda x: x in printable, data)</code>
string.printable セットには、数字、文字、記号、スペース、ピリオドなど、システム上で印刷可能なすべての文字が含まれます。このセットをフィルターとして使用すると、文字列からすべての印刷不可能な文字を削除できます。
たとえば、文字列「somex00string.withx15 funkycharacters」がある場合:
<code class="python">s = "some\x00string. with\x15 funny characters" ''.join(filter(lambda x: x in printable, s))</code>
結果は次のようになります。
'somestring. with funny characters'
このメソッドは、スペースとピリオドを保持しながら非 ASCII 文字を効果的に削除し、その後の処理に使用できるクリーンな文字列を提供します。
以上がスペースとピリオドを保持したまま非 ASCII 文字を選択的に削除するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

forhandlinglaredataSetsinpython、usenumpyArrays forbetterperformance.1)numpyarraysarememory-effictientandfasterfornumericaloperations.2)nusinnnnedarytypeconversions.3)レバレッジベクトル化は、測定済みのマネージメーシェイメージーウェイズデイタイです

inpython、listsusedynamicmemoryallocation with allocation、whilenumpyArraysalocatefixedmemory.1)listsallocatemorememorythanneededededinitivative.2)numpyArrayasallocateexactmemoryforements、rededicablebutlessflexibilityを提供します。

inpython、youcanspecthedatatypeyfelemeremodelernspant.1)usenpynernrump.1)usenpynerp.dloatp.ploatm64、フォーマーpreciscontrolatatypes。

numpyisessentialfornumericalcomputinginpythonduetoitsspeed、memory efficiency、andcomprehensivematicalfunctions.1)それは、performsoperations.2)numpyArraysaremoremory-efficientthanpythonlists.3)Itofderangeofmathematicaloperty

contiguousMemoryAllocationisucial forArraysは、ForeffienceAndfastelementAccess.1)iteenablesConstantTimeAccess、O(1)、DuetodirectAddresscalculation.2)itemprovesefficiencyByAllowingMultiblementFechesperCacheLine.3)itimplifieMememm

slicingapythonlistisdoneusingtheyntaxlist [start:stop:step] .hore'showitworks:1)startisthe indexofthefirstelementtoinclude.2)spotisthe indexofthefirmenttoeexclude.3)staptistheincrementbetbetinelements

numpyallows forvariousoperationsonarrays:1)basicarithmeticlikeaddition、減算、乗算、および分割; 2)AdvancedperationssuchasmatrixMultiplication;

Arraysinpython、特にnumpyandpandas、aresentialfordataanalysis、offeringspeedandeficiency.1)numpyarraysenable numpyarraysenable handling forlaredatasents andcomplexoperationslikemoverages.2)Pandasextendsnumpy'scapabivitieswithdataframesfortruc


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

mPDF
mPDF は、UTF-8 でエンコードされた HTML から PDF ファイルを生成できる PHP ライブラリです。オリジナルの作者である Ian Back は、Web サイトから「オンザフライ」で PDF ファイルを出力し、さまざまな言語を処理するために mPDF を作成しました。 HTML2FPDF などのオリジナルのスクリプトよりも遅く、Unicode フォントを使用すると生成されるファイルが大きくなりますが、CSS スタイルなどをサポートし、多くの機能強化が施されています。 RTL (アラビア語とヘブライ語) や CJK (中国語、日本語、韓国語) を含むほぼすべての言語をサポートします。ネストされたブロックレベル要素 (P、DIV など) をサポートします。

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

ホットトピック









