Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return keys in original order in a dict

I'm reading in a file and storing the info in a dict as it reads from top to bottom. I don't want to print out in a wrong order compared to the original file.

Also, a very small question: I remember seeing it somewhere a short form of the if and else statement:

if a == 'a':
    a = 'b' ? a = 'c'  

Do you know the exact form?

Thanks.

like image 360
BPm Avatar asked Sep 26 '11 22:09

BPm


1 Answers

  1. Use an OrderedDict.
  2. a = 'b' if a == 'a' else 'c'
like image 146
Mark Byers Avatar answered Oct 01 '22 11:10

Mark Byers