3

on python3 , i want to sort a list of arabic words IN THE ALPHABETIC ORDER the file i have has this content

حصل,شد
حصن,حضا
حضر,جا
حض,أكد
حضن,تهلا
حطب,حطب
حطم,هرس

and i want to sort it by the first column so the output become

حض,أكد
حصن,حضا
حطب,حطب
حضن,تهلا
حضر,جا
حصل,شد
حطم,هرس

i tried using the function sort it didn't work i think i m missing something

my code is something like that

# coding=utf-8
import csv
import sort
d=[]
with open('sort.csv', 'a+', encoding='utf-8' , newline='\n') as in_fp:
    with open('result.csv','w', encoding='utf-8' , newline='\n') as out_fp:
        for row in (csv.reader(in_fp, delimiter=',')):
            d.append=row[1]
        d.sort()

and then i want to save it in the result.csv

i found this link! but i don't it is working for me

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Maryam-O
  • 61
  • 1
  • 6
  • Can you include some code you have written? A [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) ? – loudmummer Jun 08 '18 at 04:28
  • 2
    In what way do `sort`/`sorted` not work? Is the result wrong, or is there an exception, or something else? – lenz Jun 08 '18 at 04:56
  • i have added some code above, the problem is that i don't know how to code this phrase " i want to sort based on the second column the elements of the file" – Maryam-O Jun 08 '18 at 13:22
  • i used the list d because i earlier used this line but it didn't work : csv.writer(out_fp).writerows((csv.reader(in_fp, delimiter=',').row[1]).sort()) – Maryam-O Jun 08 '18 at 13:23
  • Does this answer your question? [How to sort a list of strings?](https://stackoverflow.com/questions/36139/how-to-sort-a-list-of-strings) – Karl Knechtel Apr 26 '23 at 17:13

0 Answers0