Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dictonaries in python
01-18-2010, 06:15 PM
Post: #1
dictonaries in python
Python dictionary is just like a regular dictionary. Here is a example of a dictionary.
Code:
#############################
#This program was coded by Jerome Scott II #
#############################

#initialize dictionary name dic with a default value Arcane as a key and Confusion is the value
dic = {'Arcane': 'Confusing'};

#append to dictionary key codecaine value Jerome Scott II
dic['codecaine'] = 'Jerome Scott II';

#appending some more
dic['python'] = 'best programming langauge';

#loop version 1 k is the key and v is the value
print('loop version 1');
for k, v in dic.iteritems():
    print(k + ': ' + v);
    
#change value of python key
dic['python'] = 'Python is a beast';

#loop version 2 k is the key
print('loop version 2');
for k in dic:
    print(k + ': ' + dic[k]);

#check if a key is in the dictionary
if 'codecaine' in dic:
    print('codecaine is in the dictionary');
    print('codecaine: ' + dic['codecaine']);
Visit this user's website Find all posts by this user
Quote this message in a reply
01-18-2010, 06:17 PM
Post: #2
RE: dictonaries in python
Python really is a beast! Smile
Find all posts by this user
Quote this message in a reply
01-18-2010, 08:22 PM
Post: #3
RE: dictonaries in python
Well it is some kind of array of strings included in language. It is not hard to make, but it is good to have it included !

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: