Comparing strings in two lists and
Hi there, I am super new here and am sorry if somebody already asked similar questions, but somehow I can't find anything yet.
It should not be difficult, but I am stuck.
I have two lists: a list of words and a .csv file with two fields: Latin characters and Morse's code.
the idea is literally to translate the words into Morse's code.
I picked a random word from list 1 and used a character Node to make a list of letters.
But god, I can't really find a way to go through the lists and replace all letters in the list 1 by morse's code.
Anyone? Please? It should be straightforward, right?
|?||Show this help|
|ESC||Blurs the current field|
|r||Focus the comment reply box|
|^ + ↩||Submit the comment|
You can use
Command ⌘ instead of
Control ^ on Mac
Support Staff 1 Posted by john on 24 Oct, 2019 10:04 PM
Thanks for sharing your conundrum. NodeBox's reliance on lists takes awhile to get used to, so your confusion is not unusual.
As it turns out, there is a straightforward solution in this case. The key is to use the filter_data node. I have attached a screenshot and a working NodeBox demo for you to examine.
All you have to do is filter your Morse CSV to return all rows that match the character you want to convert. Since each character only occurs once, filter_data will always return one row each time you pass it a character. So just feed your CSV into the filter_data node, set the Key to "Character", and feed your list of character values into the Value port.
If you place the left display into Data mode your view should match my screenshot. You now have a table where each row consists of the character from your word and the corresponding Morse code string.
You can then pull out the Morse code strings in order by simply feeding this table in to a lookup node (with Key set to "Morse"). This will give you the codes as a list. Just feed that list into a text path node and stack them (East or South).
If you want, you could turn this whole thing into a subnetwork that would take a list of words as it input and spit out a formatted morse code string for each word.
Give it a try and please come back if you have any further questions. We all learn from these little exercises so I really appreciate it when people write in.
Welcome to the NodeBox community!
2 Posted by Ruben on 22 Dec, 2019 03:46 PM
Thank you very much for this fantastic application. Nodebox is one of my favorites to experiment without having too much knowledge of programming. I hope you can continue developing it and adding improvements and new features.
My first question about this example is: is there a way to make it work with lowercase letters using the nodes without having to write an external function in Python or having to add the lowercase letters to the CSV for comparison?
Support Staff 3 Posted by john on 14 Apr, 2020 08:33 PM
First, my apologies! For some reason your note was marked as spam by our system, so I did not see it until now. I have no idea why this happened.
The easiest way to make this example work with lowercase letters is to convert them to upper case using the Change Case node. Just add that one node to your source text and the above example will work fine.
Again, sorry it took so long to answer your question.