Hướng dẫn dùng mnemonic definition python

Luke Paireepinart rabidpoobear at gmail.com
Thu Jul 23 19:11:36 CEST 2009
  • Previous message: [Tutor] mnemonics to better learn Python
  • Next message: [Tutor] mnemonics to better learn Python
  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

I approach these things more along the lines of objects rather than looking
at the raw source code to remember what I'm doing.For example, I see (x, y,
z) and I think "ah, it's a little pre-packaged goodie of delicious
variables"
and when I see [x, y, z] I think "ah, it's a box with some candy at the
bottom, but there's plenty of room for me to put more.
I'm guessing all the candy is interrelated somehow because people usually
keep things that are similar in the same container"
and for dictionaries I think "hey, it's just a list that's indexed with
anything you want, instead of only integers."

I wouldn't call it "rote learning" because that would be more along the
lines of
x = {"hello": 1} # dictionary with a string as key and an integer as valuex
= {1: "hello"} # dictionary with an integer as key and a string as value
x = {1: 1} # dictionary with an integer as key and value
x = {"hello": "hello"} # dictionary with a string as key and value
.... etc.

I.E. I'm not forcing myself to learn every possibility.  I learn what
"mutability" is and then I learn what dictionaries are,
and then I understand how to use them.  I don't need mnemonics to remember
them.

I guess my point is that I see syntax more as a means for defining a
specific behavior I want, rather than as an
actual representation of the behavior.  Like, I think "I need a dictionary
here.  Oh, that's the {} thing, right?"
rather than "Oh, there needs to be {} here, I think.   Oh yeah, that's
called a dictionary"
so it doesn't really help to relate syntax to actual behavior.

I think of things on the conceptual level and translate down to Python when
I need to tell the computer how to do it.
And when I read Python code, I translate it up to conceptual level as well.

I don't see "series = form.getvalue('series').strip()" and think "okay,
there's an object called "form".  it has a method called "getvalue" and it's
getting passed "series".
Then the return value is being stripped of whitespace on both ends."

I see it and I think "okay, 'series' was passed to the program in a
user-submitted form and now it's stored in a local variable so I can
manipulate it."

On Thu, Jul 23, 2009 at 1:05 AM, David  wrote:

> Dear List,
>
> in order to memorize which Python sequences are mutable or immutable, I
> focused on the SHAPE of the brackets that are associated with each type
> of sequence.
>
> For instance, a *list* is characterised by square brackets, [].
> My mnemonic device to memorize that lists are mutable is this: "the
> brackets have sharp edges, they could be trimmed, taking their edges off".
>
> The same thing happens with *dictionaries* (which, okay, are not
> sequences). Anyway, their brackets, {}, have sharp edges, hence they are
> mutable.
>
> *Tuples*, in turn, have perfectly 'round' brackets, (), and these
> brackets obviously can't be improved upon by taking anything off them.
> Hence: tuples are immutable.
>
> That leaves us with *strings*, which are also not mutable. Here we have
> no brackets, and this particular mnemonic device breaks down.
>
> What I am interested in is finding out whether you use similar
> techniques, and if so, which ones? How, for examples, do you make sense
> of all those special characters that make regular expressions powerful?
> Do you rely on rote learning, or do you employ some other technique?
>
> I reckon that if we could come up with some tips and techniques as to
> how to uncloud the thick information fog that any beginning programmer
> has to wade through, the very first steps in learning Python could be
> made more easy.
>
> What insights can you share?
>
> Curious,
>
> David
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

  • Previous message: [Tutor] mnemonics to better learn Python
  • Next message: [Tutor] mnemonics to better learn Python
  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

More information about the Tutor mailing list

Project description

python-mnemonic

Reference implementation of BIP-0039: Mnemonic code for generating deterministic keys

Abstract

This BIP describes the implementation of a mnemonic code or mnemonic sentence – a group of easy to remember words – for the generation of deterministic wallets.

It consists of two parts: generating the mnenomic, and converting it into a binary seed. This seed can be later used to generate deterministic wallets using BIP-0032 or similar methods.

BIP Paper

See https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki for full specification

Installation

To install this library and its dependencies use:

pip install mnemonic

Usage examples

Import library into python project via:

from mnemonic import Mnemonic

Initialize class instance, picking from available dictionaries:

  • english

  • chinese_simplified

  • chinese_traditional

  • french

  • italian

  • japanese

  • korean

  • spanish

mnemo = Mnemonic(language)
mnemo = Mnemonic("english")

Generate word list given the strength (128 - 256):

words = mnemo.generate(strength=256)

Given the word list and custom passphrase (empty in example), generate seed:

seed = mnemo.to_seed(words, passphrase="")

Given the word list, calculate original entropy:

entropy = mnemo.to_entropy(words)

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

0.20 - 2021-07-27

Added

  • Type annotations

  • Support for testnet private keys

Changed

  • Project directory structure was cleaned up

  • Language on the Mnemonic object is remembered instead of repeatedly detecting

Removed

  • Support for Python 2.7 and 3.4 was dropped

0.19 - 2019-10-01

Added

  • Start of changelog

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution