I am new to python and trying to do the following. The text file contains the data in a slightly strange format, and I was wondering if there is an easy way to parse it and automatically fill the empty dictionary with the correct keys and values.
The data looks something like this:
01> A B 2
02> EWMWEM
03> C D 3
04> EWWMWWST
05> Q R 4
06> WESTMMMWW
So, each pair of lines describes a complete set of instructions for the robot arm. For lines 1-2 for arm 1, 3-4 for arm 2 and so on. The first line indicates the location, and the second line contains a set of instructions (moving, changing direction, turning, etc.).
I am looking for a way to import this text file, parse it correctly and populate a dictionary that will generate automatic keys. Note that the file contains only the value. Thatβs why itβs hard for me. How to tell the program to generate armX (where X is an identifier from 1 to n) and assign it a tuple (or pair) in such a way that the dictionary reads.
dict = {'arm1': ('A''B'2, EWMWEM) ...}
I apologize if the beginner-ish-vocals are redundant or unclear. Please let me know and I will be happy to clarify.
Easy-to-understand commented code will help me learn concepts and motivation.
Just to provide some context. The point of the program is to download all the instructions and then execute the methods on hand. Therefore, if you think there is a more elegant way to do this without downloading all the instructions, please suggest.