Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Complex Long codes
#1
Hi

Any tutorials which explains complex long codes. For examples codes which have functions and then have if statements and loops in it. Like below is the code
from nltk.tokenize import word_tokenize

# create bag-of-words
all_words = []

for message in processed:
    words = word_tokenize(message)
    for w in words:
        all_words.append(w)
        
all_words = nltk.FreqDist(all_words)
def find_features(message):
    words = word_tokenize(message)
    features = {}
    for word in word_features:
        features[word] = (word in words)
    return features
features = find_features(processed[0])
for key, value in features.items():
    if value == True:
        print key
Are there any tutorials which explain such kind of examples in detail?
Quote
#2
I don't know if there's anything exactly like you want. I mean, there's tutorials out there with code that complicated. My text adventures (link below) and CLI tutorials have code that complicated. However, they expect you know how the individual parts (loops, conditionals, functions, classes) work, so they don't bother to explain them in detail. They assume you've already done tutorials on the individual parts. The tutorials on the individual parts, on the other hand, tend to have much simple code. They want to focus on that little part.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#3
yeah again not enough explanation. And no explanation there. For example

In First code, Line 33
current_room = 'temple' 
why its not like Line32?

In 2nd code line 30,
current_room = rooms[current_room[command]]
whats going on? what is each part of this line

Also
current_room = rooms['empty']
what is rooms in this line of code
Quote
#4
ayaz786amd Wrote:why its not like Line32?

Because line 32 is a conditional (which makes a choice as to whether or not to execute a block of code), and line 33 is an assignment (which assigns a value to a variable).

ayaz786amd Wrote:whats going on? what is each part of this line

In the line current_room = rooms[current_room[command]], the first step is looking up the key in 'command' in the dictionary current_room. That value is then used as a key in the rooms dictionary, and that value is assigned to current_room.

In more abstract terms, current_room is a dictionary of room IDs keyed to directions. The direction keys return the room IDs that you would get to going in that direction. Rooms is a bunch of dictionaries like current_room keyed to their room IDs. So you use the direction (command) to get the next room ID from current_room, and then get use that room ID to get the details on the room from rooms.

ayaz786amd Wrote:what is rooms in this line of code

It is a dictionary containing information on all of the rooms in the game, as described above. If you look at the definition of rooms at the top of the code, you will see that rooms['empty'] refers to a room named 'an empty room', connected to the bedroom and the temple, with the text description 'The stone floors and walls and cold and damp.'.

As I said, that tutorial glosses over a lot of stuff. But most of that is basic stuff that you should know before attempting a to write code that complicated.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#5
which concepts falls into this code
current_room = rooms[current_room[command]]
Quote
#6
Dictionaries.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)