[Tutor] Is there a programmatic use for keys() and values()
Jim Mooney
cybervigilante at gmail.com
Sun Jun 16 02:33:20 CEST 2013
On 15 June 2013 14:55, Alan Gauld <alan.gauld at btinternet.com> wrote:
> I think your making it harder than it is.
> Just use the result as you would expect and it will work.
I just meant that since I'm learning I'll create a dictionary on the
fly to try something out. All goes well except my IDE will type two
quotes if I type one, then center the cursor in between. the same for
braces, brackets, etc. It's a great convenience. But in a dictionary
I'll get to here:
{'alpha':'beta'
Only my cursor is to the Left of the final quote. Then I have to go
hunt the Right Arrow or End key, which is a big pain since I'm far
from a perfect touch typist and they're both far from the home keys.
But I solved the problem with a simple cheat instead of writing an IDE
or python script to create a dict from a two-by-two list then just
copy it from the interpreter. Something like:
>>> myfunc(['tippecanoe','tylertoo',1,'wun','nestedlist',[[2,3],[3,5]],'float',3.41])
>>> {'tippecanoe':'tylertoo',1:'wun','nestedlist':[[2,3],[3,5]],'float':3.41}
I realized once I got to nested lists, dicts, spaces, complex objects,
and so forth, it was getting too deep for me. But it will be a good
exercise after awhile, since I can see it would require some parsing,
regexes, and recursion. Solving annoying little real-world problems
like that strikes me as a good way to learn Python - possibly better
than artificial book-exercises, or at least as an adjunct ;')
My keyboard cheat was I simply remapped Left Shift + Spacebar to move
the cursor one character right, instead. Left Shift + Spacebar is very
easy to find without looking and I Never use Left Shift + Spacebar
anyway. Now I can type fast and not hunt the stupid right arrow key.
Caps Lock gets me out of parentheses by going to End. Between those
two I'm done with the keyboard annoyance of hunting the End and Right
Arrow key . Thankfully so, since I'm about out of easy remaps. The
rest would be as troublesome as the original problem. Well, I still
have Right Shift + Spacebar. I'll save that for a special occasion.
Come to think of it Caps Lock + a letter key would be easy and give me
a dozen more functions for the most common letters, most of them
mnemonic. But that's for another day. Too many all at once would just
be going backward.
That may not seem important but while Python is fun to learn, hunting
keys far off from the home keys is annoying, at least to me. Or maybe
I'm just really lazy, since I recline way back while typing ;')
Jim
More information about the Tutor
mailing list