Ordering letters in Python

I have a list of the cards and the suit of a deck that I need to sort. Considering the correct order: A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K And the suits: P (clubs). O (gold), E (sword), C (hearts) After reading the file with all the cards of all suits, I need to sort each suit. For example: reading the file returns (I will consider only one suit):

K P
A P
3 P 
9 P
10 P
J P
4 P
2 P
6 P
8 P
7 P
Q P
5 P

I need to sort by the value of the cards. I thought I'd play in a dictionary where the keys are the cards and the value is the suit, and then sort by the key, but I can not get out of it. Can anyone help me? My code so far:

arquivo = open('nome_arquivo.txt', 'r')
dados = arquivo.readlines()
dic = {}
for linha in dados:
    linha = linha.split()
    dic[linha[0]] = linha[1]
print(dic)
Author: Gabriel Moura, 2019-04-22

1 answers

The "sorted" method returns the ascending sorted deck list.

The "enumerate" method returns the index and elements of the deck list.

The variables "k" and " v " receive the index and element of the deck list.

The "strip" method removes line breaks, whitespace, etc.from the "string".

The method " Dec.update "updates the dictionary, the key will be the variable" k "and" v " the value.

The method " Dec.get " returns the value of a key specified or empty if the key does not exist.

arquivo = open('cartas.txt', 'r')
baralho = arquivo.readlines()

dic = {}

for k, v in enumerate(sorted(baralho)):    
    v = v.strip().strip('\n').strip('P')
    dic.update({k:v})

if dic.get(0) != 'A':
    dic.update({0:'A'})

if dic.get(9) != '10':
    dic.update({9:'10'})

if dic.get(11) != 'Q':
    dic.update({11:'Q'})

if dic.get(12) != 'K':
    dic.update({12:'K'})

print(dic)
 2
Author: Éder Garcia, 2019-04-25 14:33:18