0

This codes here is that I read the file configurations first then thereafter I need to pass directory into the method known as the ednotes_extractor.get_ednotes()

 from preprocessing import ednotes_extractor

    csf_config_txt = open("..\CFS_Config.txt", "r")

    file_list = []
    root_dir = ""
    edn_txt = ""
    pcr_txt = ""

    for line in csf_config_txt:
        file_list.append(line)

    if "Folder Path = " in file_list[0]:
        root_dir = str(file_list[0])
        root_dir = root_dir.replace("Folder Path = ", "")
        root_dir = root_dir.replace("\n", "")

    if "ED Notes = " in file_list[1]:
        root_dir = str(file_list[1])
        root_dir = root_dir.replace("ED Notes = ", "")
        root_dir = root_dir.replace("\n", "")

    if "Patient Care Record = " in file_list[2]:
        root_dir = str(file_list[2])
        root_dir = root_dir.replace("Patient Care Record = ", "")
        root_dir = root_dir.replace("\n", "")

    print(file_list[2])

    def convert_txt(choices):
        if(choices == 1):
            #I would like to pass a directory in this method called theednotes_extractor 
            ednotes_extractor.get_ednotes(str2=file_list[1])
        elif(choices==2):
            print("Hi")
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Oct 01 '18 at 09:59

3 Answers3

0

Maybe this will help

arr1 = [1,2,3]
arr2 = [4,5,6]

just add both arrays without []

arr3 = arr1 + arr2

In your case

x = []
for i in range(0, len(arr_cat)):
    x += arr_cat[i]
print(len(x))

The above will suffice.

Y M
  • 2,105
  • 1
  • 22
  • 44
  • the problem is that arr_cat consists of 44 arrays and i want to combine these 44 arrays into a single array within itself which is arr_cat @mango –  Oct 01 '18 at 02:39
  • @Lynn I edited according to your needs. Does above work? – Y M Oct 01 '18 at 02:40
  • 3704 2703 5891 3505 4949 2140 2753 1557 2655 3220 2573 2935 1904 8136 2544 3219 12116 2702 3282 2243 2684 3057 3782 4091 3067 2777 1768 2603 4226 4219 2666 2791 4900 4426 3021 3032 2692 1561 2010 4209 3988 2846 3324 2397 2397 @mango my length output is this when i try the above –  Oct 01 '18 at 02:58
0

List comprehension will do it. It will unpack the list of lists and place them into a new list.

flat_list = [item for sublist in arr_cat for item in sublist]
arr_cat = flat_list
PL200
  • 741
  • 6
  • 24
0

Try this:

from itertools import chain

new_list = list(chain(*arr_cat))
Mehrdad Pedramfar
  • 10,941
  • 4
  • 38
  • 59
  • Hi @mehrdad-pedramfar it cannot work... –  Oct 01 '18 at 07:52
  • @Lynn I think that we misunderstand your desires, can you be a little more specific and share us you desired output? – Mehrdad Pedramfar Oct 01 '18 at 08:03
  • I have created another new question on this pls do check @mehrdad-pedramfar –  Oct 01 '18 at 08:05
  • @Lynn i also checked it, it works just fine for me, can you tell me what do you get from my answer? – Mehrdad Pedramfar Oct 01 '18 at 08:06
  • Traceback (most recent call last): File "C:/Users/L31307/PycharmProjects/FYP/preprocessing/ednotes_extractor.py", line 154, in get_ednotes(str2) File "C:/Users/L31307/PycharmProjects/FYP/preprocessing/ednotes_extractor.py", line 120, in get_ednotes new_list = list(chain(*new_arr)) TypeError: 'list' object is not callable @mehrdad-pedramfar i got this error –  Oct 01 '18 at 08:29
  • Ow. I think I just understand your problem, you have defined a variable named `list` in your code, don't do this, `list` is a built-in in python, change that variable name to something else like `lst`, then run the code again and update me by your result.@Lynn – Mehrdad Pedramfar Oct 01 '18 at 08:31
  • Hi @mehrdad-pedramfar the list is not callable means in ur codes list(chain(*arr_cat)) is not callable... –  Oct 01 '18 at 08:35
  • @Lynn yes, and it is because you have overridden it in your code. – Mehrdad Pedramfar Oct 01 '18 at 08:36
  • okie thanks there are no error right now but there is a small issue here because the result is not what I desired –  Oct 01 '18 at 08:40
  • what is the result and what is your desires ? – Mehrdad Pedramfar Oct 01 '18 at 08:41