User Tools

Site Tools


python:python-dictionary-comprehension

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
python:python-dictionary-comprehension [2018/06/15 19:19] – created aistispython:python-dictionary-comprehension [2018/06/15 19:20] (current) – aistis
Line 1: Line 1:
 python-dictionary-comprehension python-dictionary-comprehension
 +
 +https://www.datacamp.com/community/tutorials/python-dictionary-comprehension
  
 <code> <code>
Line 11: Line 13:
 </code> </code>
  
 +<code>
 dict1_keys = {k*2:v for (k,v) in dict1.items()} dict1_keys = {k*2:v for (k,v) in dict1.items()}
 print(dict1_keys) print(dict1_keys)
  
 {'dd': 4, 'ee': 5, 'aa': 1, 'bb': 2, 'cc': 3} {'dd': 4, 'ee': 5, 'aa': 1, 'bb': 2, 'cc': 3}
 +</code>
  
 +
 +<code>
 +c2 = {k:{'S':c[k]} for k in c}
 +
 +c2 = {k:{'N' if k=='id' else 'S':v} for (k,v) in c.items()} 
 +
 +</code>
python/python-dictionary-comprehension.1529079599.txt.gz · Last modified: by aistis