0

Suppose I have the next path:

path=[case1_Qxxx_cap1_whatever.csv,case1_Qxxx_cap1_whatever2.csv,case1_Qxxx_cap1_whatever3.csv,....,case1_Qxxx_cap2_whatever.csv,case1_Qxxx_cap2_whatever2.csv,case1_Qxxx_cap2_whatever3.csv,case2_Qxxx_cap1_whatever.csv,case2_Qxxx_cap1_whatever2.csv,...,case2_Qxxx_cap2_whatever.csv,case2_Qxxx_cap2_whatever2.csv]

I would like to have this:

pathf=[[[case1_Qxxx_cap1_whatever.csv,case1_Qxxx_cap1_whatever2.csv,...],[case1_Qxxx_cap2_whatever.csv,Qxxx_cap2_whatever2.csv,...]],[[case2_Qxxx_cap1_whatever.csv,case2_Qxxx_cap1_whatever2.csv,...],[case2_Qxxx_cap2_whatever.csv,case2_Qxxx_cap2_whatever2.csv,...]]]

How can I do it?....

I used this code:

d = {}
for path in parameters:
    ci=path.split('/')[-1].split('_')[0]
#    ci=parameters[-1].split('/')[-1].split('..')[0][:-2]
    if ci not in d:
        d[ci] = [path]        
    else:
        d[ci].append(path)
pathlistf = []
for key in d:
    pathlistf.append(d[key])

And my results where next:

pathlistf=[[C:/Users/1017249739/Desktop/DATOS/Caso1_Q2660_Cap1_0.0.csv,
C:/Users/1017249739/Desktop/DATOS/Caso1_Q2660_Cap1_0.1.csv,
C:/Users/1017249739/Desktop/DATOS/Caso1_Q2660_Cap1_0.10.csv,...
C:/Users/1017249739/Desktop/DATOS/Caso1_Q2660_Cap2_0..0.75.csv,
C:/Users/1017249739/Desktop/DATOS/Caso1_Q2660_Cap2_0..0.76.csv,
C:/Users/1017249739/Desktop/DATOS/Caso1_Q2660_Cap2_0..0.77.csv,
C:/Users/1017249739/Desktop/DATOS/Caso1_Q2660_Cap2_0..0.78.csv],
[C:/Users/1017249739/Desktop/DATOS/Caso2_Q2660_Cap1_0..0.53.csv,
C:/Users/1017249739/Desktop/DATOS/Caso2_Q2660_Cap1_0..0.54.csv,
C:/Users/1017249739/Desktop/DATOS/Caso2_Q2660_Cap1_0..0.55.csv,
C:/Users/1017249739/Desktop/DATOS/Caso2_Q2660_Cap1_0..0.56.csv,
C:/Users/1017249739/Desktop/DATOS/Caso2_Q2660_Cap4_0..0..0..0..0.94.csv,
C:/Users/1017249739/Desktop/DATOS/Caso2_Q2660_Cap4_0..0..0..0..0.95.csv,
C:/Users/1017249739/Desktop/DATOS/Caso2_Q2660_Cap4_0..0..0..0..0.96.csv]]

my wish is get something like this:

pathff=[[[C:/Users/1017249739/Desktop/DATOS/Caso1_Q2660_Cap1_0.0.csv,
C:/Users/1017249739/Desktop/DATOS/Caso1_Q2660_Cap1_0.1.csv,
C:/Users/1017249739/Desktop/DATOS/Caso1_Q2660_Cap1_0.10.csv,...],
[C:/Users/1017249739/Desktop/DATOS/Caso1_Q2660_Cap2_0..0.75.csv,
C:/Users/1017249739/Desktop/DATOS/Caso1_Q2660_Cap2_0..0.76.csv,
C:/Users/1017249739/Desktop/DATOS/Caso1_Q2660_Cap2_0..0.77.csv,
C:/Users/1017249739/Desktop/DATOS/Caso1_Q2660_Cap2_0..0.78.csv]],
[[C:/Users/1017249739/Desktop/DATOS/Caso2_Q2660_Cap1_0..0.53.csv,
C:/Users/1017249739/Desktop/DATOS/Caso2_Q2660_Cap1_0..0.54.csv,
C:/Users/1017249739/Desktop/DATOS/Caso2_Q2660_Cap1_0..0.55.csv,
C:/Users/1017249739/Desktop/DATOS/Caso2_Q2660_Cap1_0..0.56.csv,...],
[C:/Users/1017249739/Desktop/DATOS/Caso2_Q2660_Cap4_0..0..0..0..0.94.csv,
C:/Users/1017249739/Desktop/DATOS/Caso2_Q2660_Cap4_0..0..0..0..0.95.csv,
C:/Users/1017249739/Desktop/DATOS/Caso2_Q2660_Cap4_0..0..0..0..0.96.csv]]]

I appreciate your helping

  • or there is another way using dataframe or another similar thing to have that filters... i appreciate your help – Julian Andres Lastra Garcia Feb 10 '20 at 23:25
  • 1
    What have you tried, and what exactly is the problem with it? – jonrsharpe Feb 10 '20 at 23:27
  • i used this ```d = {} for path in parameters: ci=path.split('/')[-1].split('_')[0] # ci=parameters[-1].split('/')[-1].split('..')[0][:-2] if ci not in d: d[ci] = [path] else: d[ci].append(path) pathlistf = [] for key in d: pathlistf.append(d[key]) ``` – Julian Andres Lastra Garcia Feb 10 '20 at 23:29
  • 1
    [Edit] the question to give a [mcve]. What's the *problem* with that code? – jonrsharpe Feb 10 '20 at 23:30
  • Also: what's the problem with the answers you got [last time](https://stackoverflow.com/questions/60128506/how-to-save-a-list-of-string-in-sublists-according-specific-expression) you asked this? You said what you're now apparently asking for help fixing is exactly what you wanted. – jonrsharpe Feb 10 '20 at 23:33
  • There is also [this](https://stackoverflow.com/questions/13368723/python-split-a-list-into-subsets-based-on-pattern) which wouldn't take much adaptation to apply to your problem. – Paul Rooney Feb 10 '20 at 23:35
  • 1
    Does this answer your question? [How to save a list of string in sublists according specific expression?](https://stackoverflow.com/questions/60128506/how-to-save-a-list-of-string-in-sublists-according-specific-expression) – sudo97 Feb 10 '20 at 23:37
  • no exactly, my wish is regroup that list obtained with code in another sublist as i showed in question, is to say i need a group in this way: ```pathf=[[[case1_cap1_xxx.csv,case1_cap1_yyy.csv],[case1_cap2_xxx,case1_cap2_yyyy]],...[list case i[case i cap j]]]``` – Julian Andres Lastra Garcia Feb 10 '20 at 23:51

0 Answers0