0
how to convert the list wih string values into 2d Array
Here is the input pylist = ["1.b","1.b","2.b",2.c",3.b"] the output would like this ("1", "b,b") ("2", "b,c") ("3","b")
4 Answers
+ 4
Siva Pitchai ,
have you already done a try by yourself? if not, please do so.
in any case:
=> please put your code in playground and link it here.
thanks!
+ 3
i have a version very similar to visph's, but using a dictionary instead of a list.
input:
['1.b', '1.b', '2.b', '2.c', '3.b', '1.c', '12.a']
output:
('1', 'b,b,c')
('2', 'b,c')
('3', 'b')
('12', 'a')
+ 2
If there was another item in pylist at end like "1.c", so then output for first array would be ("1", "b, b, c") ?
+ 1
Siva Pitchai you must:
1) create a new list to store result
2) iterate over pylist and for each item:
a) split string at dot
b) search if new list contains an item with first value equals to first value of splited string:
⢠if so, update second value to append second value of splited string
⢠if not, append a new item to new string with splited string
3) finally sort new list by first value in items
4) output the new list content formated as you want