samedi 9 janvier 2016

Search replace patterns in a Python list

Vote count: 0

I have a list of Rubik's Cube movements and a dictionary of shortcuts like this :

mvts = ['U', 'U', 'R', 'Ri', 'L2', ...]
shortcuts = {'UU' : 'U2', 'RRi' : '', ...}

What I'm trying to do is applying a "search and replace" on the mvts list based on the contents of shortcuts.

Here is what the result would be in the example :

mvts = ['U2', 'L2', ...]

I'm using Python3 and I can't use a library that doesn't come with Python from scratch.

I'm stuck. I can do this with some regex on a String but I don't see how to make this search quick on my list.

asked 35 secs ago

This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at http://ift.tt/jcXqJW.



Search replace patterns in a Python list

Aucun commentaire:

Enregistrer un commentaire