Comparing strings in two lists and

Oselva's Avatar

Oselva

24 Oct, 2019 03:59 PM

Hello,
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?

  1. Support Staff 1 Posted by john on 24 Oct, 2019 10:04 PM

    john's Avatar

    Dear Oselva,

    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!

    John

  2. 2 Posted by Ruben on 22 Dec, 2019 03:46 PM

    Ruben's Avatar

    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?

     TIA

  3. Support Staff 3 Posted by john on 14 Apr, 2020 08:33 PM

    john's Avatar

    Hi Ruben,

    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.

    John

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • Screenshot_2019-10-24_10.41.00.png 21.3 KB
  • Screenshot_2019-10-24_10.40.43.png 104 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

30 Sep, 2022 11:36 PM
17 Sep, 2022 08:43 AM
13 Sep, 2022 09:41 AM
08 Sep, 2022 08:08 AM
07 Sep, 2022 08:48 AM

 

03 Sep, 2022 04:11 AM
25 Aug, 2022 05:07 AM
21 Aug, 2022 07:08 PM
05 Aug, 2022 05:24 AM
02 Aug, 2022 06:57 PM
01 Aug, 2022 02:02 PM