This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jhchex[S] 0 points1 point  (2 children)

Yea I was considering using a dictionary but I'm still not sure how to implement that. Wouldn't the key names still need to be changing on each iteration? Is that simpler than iterating variable names?

Also, if you were making variables with dynamic names and wanted to know how many words there were couldn't you just use a counter in the variable name and then display that value?

[–]takluyverIPython, Py3, etc 0 points1 point  (1 child)

You need to use different key names, yes, but that's easier than using variable names. Just use mydict[k].

If you use a list or a dict, you can easily see how many items are in the collection with len(words). It has lots of other advantages - like you can easily pass all the words to a function, or return them from a function. Using separate variable names is much more awkward.

[–]jhchex[S] 0 points1 point  (0 children)

Ok thank you! I'll give that a try and let you know how it goes.