0

I would like to write this python dictionnary in just one line. Also, would it be more efficient to write it in just one line or to leave it as I wrote it so far and why ? Here is my code :

def buildDic(df):
    dic = {}
    hashSet = set(['aa','bb','cc','dd','aa'])
    for hashs in hashSet :
        dic[hashs]=0
    return dic

Thanks

Dirty_Fox
  • 1,611
  • 4
  • 20
  • 24
  • `d ={n: n**2 for n in range(5)}` for details you could refer http://www.bogotobogo.com/python/python_dictionary_comprehension_with_zip_from_list.php – Pavan Gupta Oct 22 '15 at 08:03
  • 1
    Use [`fromkeys`](https://docs.python.org/2/library/stdtypes.html#dict.fromkeys): `dict.fromkeys(hashSet, 0)` – BioGeek Oct 22 '15 at 08:24

0 Answers0