Question: How to convert print to screen output to List format [ ]... Help, please.

I wish to process a string of letters into a list of one or more characters which are comma separated at each change of character. The following function will achieve this, but its output is not as list [ ] in the format required.  

Below is a routine to split a character string based on change of character: (ref: https://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character#Maple)

splitChange := proc (str::string) local start, i, len; start := 1; len := StringTools:-Length(str); for i from 2 to len do if str[i] <> str[start] then printf("%s, ", str[start .. i-1]); start := i end if end do; printf("%s", str[start .. len]) end proc;
splitChange("WPKCPYWYYYXHYY");# 

Here is the output:
W, P, K, C, P, Y, W, YYY, X, H, YY

This print-to screen output is not usable, instead I need the output in list format i.e. ListY:= ["W", "P", "K", "C", "P", "Y", "W", "YYY", "X", "H", "YY"].

Background

 In my model, each of these character strings is a node of a graph, and their adjacencies represent an edges of a graph.  I aim to automatically map strings into a set of directed adjacencies as output; for example:  

AdjSet:= {[W, P], [P, K], [K, C], [C, P], [P, Y], [Y, W], [W,YYY],[YYY, X], [X, H], [H,YY]}.

This set will be the input to a directed graph, e.g: 
M := Digraph(AdjSet); DrawGraph(M);
from which our objective, the adjacency matrix of the nodes can be obtained in MAPLE.  

Help

Can someone please help me by modifying the SplitChange rountine so that it produces output in the form of ListY above? 

Thanks in anticipation of your help

Melvin Brown
 

Please Wait...