そこで、Python で作成したリストを HTML 形式で JavaScript として記述できるようにフォーマットする手順を作成しました。このように見えます
from django.template.defaultfilters import slugify
def js_format(cars):
new_cars = []
for car in cars:
car = str(slugify(car))+'|'+car
new_cars.append(car)
return new_cars
dodge = ["Avenger","Caliber","Caravan","Challenger","Colt","D150","D250","D350","Dakota","Dart","Daytona","Durango","Durango Hybrid","Dynasty","Grand Caravan","Intrepid","Journey","Magnum","Monaco","Neon","Nitro","Omni","Raider","Ram 1500","Ram 2500","Ram 3500","Ram 50","Ram Van","Ram Wagon","Ramcharger","Shadow","Sprinter","SRT Viper","Spirit","Stealth","Stratus","Viper","W150","W250","W350"]
「回避」リストの手順を使用すると...
>>> js_format(dodge)
['avenger|Avenger', 'caliber|Caliber', 'caravan|Caravan', 'challenger|Challenger', 'colt|Colt', 'd150|D150', 'd250|D250', 'd350|D350', 'dakota|Dakota', 'dart|Dart', 'daytona|Daytona', 'durango|Durango', 'durango-hybrid|Durango Hybrid', 'dynasty|Dynasty', 'grand-caravan|Grand Caravan', 'intrepid|Intrepid', 'journey|Journey', 'magnum|Magnum', 'monaco|Monaco', 'neon|Neon', 'nitro|Nitro', 'omni|Omni', 'raider|Raider', 'ram-1500|Ram 1500', 'ram-2500|Ram 2500', 'ram-3500|Ram 3500', 'ram-50|Ram 50', 'ram-van|Ram Van', 'ram-wagon|Ram Wagon', 'ramcharger|Ramcharger', 'shadow|Shadow', 'sprinter|Sprinter', 'srt-viper|SRT Viper', 'spirit|Spirit', 'stealth|Stealth', 'stratus|Stratus', 'viper|Viper', 'w150|W150', 'w250|W250', 'w350|W350']
リスト内の各項目を二重引用符で囲む必要があることを除いて、すべてが希望どおりにフォーマットされています。Pythonは一重引用符と二重引用符を同等に認識するため、Pythonで引用符を変更する方法がわかりません。どんな助けでも大歓迎です。
私の質問をご覧いただきありがとうございます