Coucou tout le monde,

J'ai un petit problème dans mon code car j'ai beaucoup de répétitions, que je pense que l'on pourrait éviter! Il s'agit d'optimiser mon code.

Voici mon code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
			for dict in list_params:
				if DCC <> "":
					if 'dccAccession' in dict and dict['dccAccession'] == DCC:
						n = n + 1
						if dict['view'] == 'RawData' or dict['type'] == 'fastq':
							rawData.append(dict['type']+' = '+dict['url'])		# fastq URLs are added
						elif dict['type'] <> 'bai':
							treatedData.append(dict['type']+' = '+dict['url'])	# Processed data URLs are added
				else:
					# Check if other parameters of the list of files are the same as in the summary file
					if ('datatype' in dict and dict['dataType'].lower() == dataT.replace('-','').lower()
						and dict['strain'] == strain and dict['cell'] == cellT and dict['grant'] == grant
						and dict['lab'] == lab and dict['age'] == age):
						if 'treatment' in dict and dict['treatment'] == treatment:
							if antibody <> "" and 'antibody' in dict and dict['antibody'] == antibody:
								if control <> "" and 'control' in dict and dict['control'] == control:
									if dict['view'] == 'RawData' or dict['type'] == 'fastq':
										rawData.append(dict['type']+' = '+dict['url'])		# fastq URLs are added
									elif dict['type'] <> 'bai':
										treatedData.append(dict['type']+' = '+dict['url'])	# Processed data URLs are added
								elif control == "":
									if dict['view'] == 'RawData' or dict['type'] == 'fastq':
										rawData.append(dict['type']+' = '+dict['url'])		# fastq URLs are added
									elif dict['type'] <> 'bai':
										treatedData.append(dict['type']+' = '+dict['url'])	# Processed data URLs are added
							elif antibody == "":
								if dict['view'] == 'RawData' or dict['type'] == 'fastq':
									rawData.append(dict['type']+' = '+dict['url'])		# fastq URLs are added
								elif dict['type'] <> 'bai':
									treatedData.append(dict['type']+' = '+dict['url'])	# Processed data URLs are added
						elif not('treatment' in dict):
							if dict['view'] == 'RawData' or dict['type'] == 'fastq':
								rawData.append(dict['type']+' = '+dict['url'])		# fastq URLs are added
							elif dict['type'] <> 'bai':
								treatedData.append(dict['type']+' = '+dict['url'])	# Processed data URLs are added
Quelqu'un aurait il une idée pour ne pas me répéter un peu trop avec :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
if dict['view'] == 'RawData' or dict['type'] == 'fastq':
							rawData.append(dict['type']+' = '+dict['url'])		# fastq URLs are added
						elif dict['type'] <> 'bai':
							treatedData.append(dict['type']+' = '+dict['url'])	# Processed data URLs are added
Merci d'avance