hi friends!
i was searching for a base conversion script in python when i was stumped with the following code snippet
>>> number = 1000
>>> hex2bin = {"0":"0000", "1":"0001", "2":"0010", "3":"0011",
"4":"0100", "5":"0101", "6":"0110", "7":"0111",
"8":"1000", "9":"1001", "A":"1010", "B":"1011",
"C":"1100", "D":"1101", "E":"1110", "F":"1111"}
>>> "".join([hex2bin[h] for h in '%X'%number]).lstrip('0')
'1111101000'
now i made my own base converter but the code above had some points i didn't understand, and i was hoping if you guys can assist me in understanding it.
1)"".join method, to which string are we calling .join??
2)[hex2bin[h] for h in '%X'%number], hex2bin is a dictionary, which is using some generator expression or string formatters or list comprehensions to generate data. how it works? where can i find more about it? what is it called?
can anyone of you please help me out with it?
thanks and regards
Anirudh (python newbie)