Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Prog challange ngrams

Name: Anonymous 2011-03-26 8:19

In the language of your choice list in order of frequency bi-grams and tri-grams posted to /prog/.

Name: Anonymous 2011-03-26 11:06


a = 3

def foo():
    a = 2

foo()    # foo should set the outer a to 2
print a  # so this should print '2'


This prints 3, because foo() didn't modify the variable in the enclosing scope. foo() can read the value of a from the outer scope; it just can't write to it, unless you use an explicit global declaration inside foo, or you write to the globals dictionary directly, like so:


a = 3

def foo():
    globals()['a'] = 2

foo()    # foo should set the outer a to 2
print a  # so this should print '2'

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List