Python: Make my code efficient and less time complexity, My Code is about fetch details from Excel using...











up vote
-3
down vote

favorite
1












I have this code so far:




Dictionary: which has Excel Data




DATA_DICT = {
'1238': {
'ipAddrPrim': ['IP1', 'IP2', 'IP3'],
'mmeName': ['N1', None, 'N3'],
's1LinkStatus': ['available', 'unavailable', 'available']
},
'1236': {
'ipAddrPrim': ['IP1', 'IP4'],
'mmeName': ['N4', 'N5'],
's1LinkStatus': ['available', 'available']
},
'1238': {
'ipAddrPrim': ['IP3', 'IP4', 'IP5'],
'mmeName': ['N7', 'N9', None],
's1LinkStatus': ['available', 'available', 'unavailable']
},
....
}



My Code: which it'll give the source and target lists




def finding_distinct_ips():
result_list, source_list, target_list, src_mrbts_key = , , ,
unique_mrbts_list = remove_duplicates(MRBTS) #MRBTS has all MRBTS ids [1234,1234,1234,1236,1236,1238,1238,1238]
#remove_duplicates(MRBTS) -> [1234,1236,1238]
for mrbts_id in unique_mrbts_list:
rest = {k: v for k, v in DATA_DICT.items() if k != mrbts_id}
main_key_ip_list = DATA_DICT[mrbts_id].get('ipAddrPrim')
status = DATA_DICT[mrbts_id].get('s1LinkStatus')
mme_name = DATA_DICT[mrbts_id].get('mmeName')
for key, val in rest.items():
rest_key_ip_list = val['ipAddrPrim']
result = compare(main_key_ip_list, rest_key_ip_list) #--> lst3 = list(set(main_key_ip_list) - set(rest_key_ip_list))
for ip_addr in result:
ip_row_index = main_key_ip_list.index(ip_addr)
if ip_addr != and status[ip_row_index] != 'unavailable':
mme_at_ip = mme_name[ip_row_index]
result_list = (mrbts_id, key, mme_at_ip, ip_addr)
if result_list[0:2][::-1] not in src_mrbts_key:
src_mrbts_key.append(result_list[0:2])
source_list.append(result_list)
else:
target_list.append(result_list)
return source_list, target_list



Explanation:




I have an Excel spreadsheet:



MRBTS  IPs  NAMES STATUS
1234 IP1 N1 Yes
1234 IP2 - No
1234 IP3 N3 Yes
1236 IP1 N4 Yes
1236 IP4 N5 Yes
1238 IP3 N7 Yes
1238 IP4 N9 Yes
1238 IP5 - No



My Code will full fill these requirements:




1) I need to compare each MRBTS with each other just like



comp(1234,1236),comp(1234,1238),comp(1236,1234),comp(1236,1238),comp(1238,1234),comp(1238,1236),...] but not with same mrbts like comp(1234,1234).



2) Lets take (if status=Yes) for comp(1236,1238): In 1236's I have some list(IPs[IP1,IP4] and Ns[N4,N5]) so again i need to compare those list with 1238's list(IP[IP3,IP4] and Ns[N7,N9]) {Here we didn't considered IP5 as status = No}, if any IP in 1236(IP list) is not found in 1238(IP list) then return that IP,Name and only if status=Yes



compare(1236,1238) = [1236,IP1,N4] and compare(1238,1236) = [1238,IP3,N7]


3) Now do the comparison for all combis and get results and store like source = [compare(1236,1238)] and target = [compare(1238,1236)] Note: Here we can observe source has right ordered comparison and target has reverse ordered comparison.




Now I want, help to make above code efficient and less the time complexity:




Note:



i. Avoid Nested for loops as my Original excel has a huge number of data it'll take time to read, else if u use then make execution fast.



ii. Use openpyxl or pyxlsb packages only










share|improve this question







New contributor




Deepika is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











closed as off-topic by stovfl, DanielBarbarian, Charlie Clark, Unheilig, greg-449 Nov 21 at 11:55



  • This question does not appear to be about programming within the scope defined in the help center.

If this question can be reworded to fit the rules in the help center, please edit the question.













  • I think you should add post in codereview.stackexchange.com
    – mehrdad-pedramfar
    Nov 21 at 6:17












  • @mehrdad-pedramfar What makes the difference?
    – Deepika
    Nov 21 at 6:19










  • That community is built for your problem Code Review.
    – mehrdad-pedramfar
    Nov 21 at 6:20






  • 1




    ok, thank you I'll post there
    – Deepika
    Nov 21 at 6:22






  • 2




    I'm voting to close this question as off-topic because should be moved to codereview.stackexchange.com
    – stovfl
    Nov 21 at 7:35















up vote
-3
down vote

favorite
1












I have this code so far:




Dictionary: which has Excel Data




DATA_DICT = {
'1238': {
'ipAddrPrim': ['IP1', 'IP2', 'IP3'],
'mmeName': ['N1', None, 'N3'],
's1LinkStatus': ['available', 'unavailable', 'available']
},
'1236': {
'ipAddrPrim': ['IP1', 'IP4'],
'mmeName': ['N4', 'N5'],
's1LinkStatus': ['available', 'available']
},
'1238': {
'ipAddrPrim': ['IP3', 'IP4', 'IP5'],
'mmeName': ['N7', 'N9', None],
's1LinkStatus': ['available', 'available', 'unavailable']
},
....
}



My Code: which it'll give the source and target lists




def finding_distinct_ips():
result_list, source_list, target_list, src_mrbts_key = , , ,
unique_mrbts_list = remove_duplicates(MRBTS) #MRBTS has all MRBTS ids [1234,1234,1234,1236,1236,1238,1238,1238]
#remove_duplicates(MRBTS) -> [1234,1236,1238]
for mrbts_id in unique_mrbts_list:
rest = {k: v for k, v in DATA_DICT.items() if k != mrbts_id}
main_key_ip_list = DATA_DICT[mrbts_id].get('ipAddrPrim')
status = DATA_DICT[mrbts_id].get('s1LinkStatus')
mme_name = DATA_DICT[mrbts_id].get('mmeName')
for key, val in rest.items():
rest_key_ip_list = val['ipAddrPrim']
result = compare(main_key_ip_list, rest_key_ip_list) #--> lst3 = list(set(main_key_ip_list) - set(rest_key_ip_list))
for ip_addr in result:
ip_row_index = main_key_ip_list.index(ip_addr)
if ip_addr != and status[ip_row_index] != 'unavailable':
mme_at_ip = mme_name[ip_row_index]
result_list = (mrbts_id, key, mme_at_ip, ip_addr)
if result_list[0:2][::-1] not in src_mrbts_key:
src_mrbts_key.append(result_list[0:2])
source_list.append(result_list)
else:
target_list.append(result_list)
return source_list, target_list



Explanation:




I have an Excel spreadsheet:



MRBTS  IPs  NAMES STATUS
1234 IP1 N1 Yes
1234 IP2 - No
1234 IP3 N3 Yes
1236 IP1 N4 Yes
1236 IP4 N5 Yes
1238 IP3 N7 Yes
1238 IP4 N9 Yes
1238 IP5 - No



My Code will full fill these requirements:




1) I need to compare each MRBTS with each other just like



comp(1234,1236),comp(1234,1238),comp(1236,1234),comp(1236,1238),comp(1238,1234),comp(1238,1236),...] but not with same mrbts like comp(1234,1234).



2) Lets take (if status=Yes) for comp(1236,1238): In 1236's I have some list(IPs[IP1,IP4] and Ns[N4,N5]) so again i need to compare those list with 1238's list(IP[IP3,IP4] and Ns[N7,N9]) {Here we didn't considered IP5 as status = No}, if any IP in 1236(IP list) is not found in 1238(IP list) then return that IP,Name and only if status=Yes



compare(1236,1238) = [1236,IP1,N4] and compare(1238,1236) = [1238,IP3,N7]


3) Now do the comparison for all combis and get results and store like source = [compare(1236,1238)] and target = [compare(1238,1236)] Note: Here we can observe source has right ordered comparison and target has reverse ordered comparison.




Now I want, help to make above code efficient and less the time complexity:




Note:



i. Avoid Nested for loops as my Original excel has a huge number of data it'll take time to read, else if u use then make execution fast.



ii. Use openpyxl or pyxlsb packages only










share|improve this question







New contributor




Deepika is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











closed as off-topic by stovfl, DanielBarbarian, Charlie Clark, Unheilig, greg-449 Nov 21 at 11:55



  • This question does not appear to be about programming within the scope defined in the help center.

If this question can be reworded to fit the rules in the help center, please edit the question.













  • I think you should add post in codereview.stackexchange.com
    – mehrdad-pedramfar
    Nov 21 at 6:17












  • @mehrdad-pedramfar What makes the difference?
    – Deepika
    Nov 21 at 6:19










  • That community is built for your problem Code Review.
    – mehrdad-pedramfar
    Nov 21 at 6:20






  • 1




    ok, thank you I'll post there
    – Deepika
    Nov 21 at 6:22






  • 2




    I'm voting to close this question as off-topic because should be moved to codereview.stackexchange.com
    – stovfl
    Nov 21 at 7:35













up vote
-3
down vote

favorite
1









up vote
-3
down vote

favorite
1






1





I have this code so far:




Dictionary: which has Excel Data




DATA_DICT = {
'1238': {
'ipAddrPrim': ['IP1', 'IP2', 'IP3'],
'mmeName': ['N1', None, 'N3'],
's1LinkStatus': ['available', 'unavailable', 'available']
},
'1236': {
'ipAddrPrim': ['IP1', 'IP4'],
'mmeName': ['N4', 'N5'],
's1LinkStatus': ['available', 'available']
},
'1238': {
'ipAddrPrim': ['IP3', 'IP4', 'IP5'],
'mmeName': ['N7', 'N9', None],
's1LinkStatus': ['available', 'available', 'unavailable']
},
....
}



My Code: which it'll give the source and target lists




def finding_distinct_ips():
result_list, source_list, target_list, src_mrbts_key = , , ,
unique_mrbts_list = remove_duplicates(MRBTS) #MRBTS has all MRBTS ids [1234,1234,1234,1236,1236,1238,1238,1238]
#remove_duplicates(MRBTS) -> [1234,1236,1238]
for mrbts_id in unique_mrbts_list:
rest = {k: v for k, v in DATA_DICT.items() if k != mrbts_id}
main_key_ip_list = DATA_DICT[mrbts_id].get('ipAddrPrim')
status = DATA_DICT[mrbts_id].get('s1LinkStatus')
mme_name = DATA_DICT[mrbts_id].get('mmeName')
for key, val in rest.items():
rest_key_ip_list = val['ipAddrPrim']
result = compare(main_key_ip_list, rest_key_ip_list) #--> lst3 = list(set(main_key_ip_list) - set(rest_key_ip_list))
for ip_addr in result:
ip_row_index = main_key_ip_list.index(ip_addr)
if ip_addr != and status[ip_row_index] != 'unavailable':
mme_at_ip = mme_name[ip_row_index]
result_list = (mrbts_id, key, mme_at_ip, ip_addr)
if result_list[0:2][::-1] not in src_mrbts_key:
src_mrbts_key.append(result_list[0:2])
source_list.append(result_list)
else:
target_list.append(result_list)
return source_list, target_list



Explanation:




I have an Excel spreadsheet:



MRBTS  IPs  NAMES STATUS
1234 IP1 N1 Yes
1234 IP2 - No
1234 IP3 N3 Yes
1236 IP1 N4 Yes
1236 IP4 N5 Yes
1238 IP3 N7 Yes
1238 IP4 N9 Yes
1238 IP5 - No



My Code will full fill these requirements:




1) I need to compare each MRBTS with each other just like



comp(1234,1236),comp(1234,1238),comp(1236,1234),comp(1236,1238),comp(1238,1234),comp(1238,1236),...] but not with same mrbts like comp(1234,1234).



2) Lets take (if status=Yes) for comp(1236,1238): In 1236's I have some list(IPs[IP1,IP4] and Ns[N4,N5]) so again i need to compare those list with 1238's list(IP[IP3,IP4] and Ns[N7,N9]) {Here we didn't considered IP5 as status = No}, if any IP in 1236(IP list) is not found in 1238(IP list) then return that IP,Name and only if status=Yes



compare(1236,1238) = [1236,IP1,N4] and compare(1238,1236) = [1238,IP3,N7]


3) Now do the comparison for all combis and get results and store like source = [compare(1236,1238)] and target = [compare(1238,1236)] Note: Here we can observe source has right ordered comparison and target has reverse ordered comparison.




Now I want, help to make above code efficient and less the time complexity:




Note:



i. Avoid Nested for loops as my Original excel has a huge number of data it'll take time to read, else if u use then make execution fast.



ii. Use openpyxl or pyxlsb packages only










share|improve this question







New contributor




Deepika is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have this code so far:




Dictionary: which has Excel Data




DATA_DICT = {
'1238': {
'ipAddrPrim': ['IP1', 'IP2', 'IP3'],
'mmeName': ['N1', None, 'N3'],
's1LinkStatus': ['available', 'unavailable', 'available']
},
'1236': {
'ipAddrPrim': ['IP1', 'IP4'],
'mmeName': ['N4', 'N5'],
's1LinkStatus': ['available', 'available']
},
'1238': {
'ipAddrPrim': ['IP3', 'IP4', 'IP5'],
'mmeName': ['N7', 'N9', None],
's1LinkStatus': ['available', 'available', 'unavailable']
},
....
}



My Code: which it'll give the source and target lists




def finding_distinct_ips():
result_list, source_list, target_list, src_mrbts_key = , , ,
unique_mrbts_list = remove_duplicates(MRBTS) #MRBTS has all MRBTS ids [1234,1234,1234,1236,1236,1238,1238,1238]
#remove_duplicates(MRBTS) -> [1234,1236,1238]
for mrbts_id in unique_mrbts_list:
rest = {k: v for k, v in DATA_DICT.items() if k != mrbts_id}
main_key_ip_list = DATA_DICT[mrbts_id].get('ipAddrPrim')
status = DATA_DICT[mrbts_id].get('s1LinkStatus')
mme_name = DATA_DICT[mrbts_id].get('mmeName')
for key, val in rest.items():
rest_key_ip_list = val['ipAddrPrim']
result = compare(main_key_ip_list, rest_key_ip_list) #--> lst3 = list(set(main_key_ip_list) - set(rest_key_ip_list))
for ip_addr in result:
ip_row_index = main_key_ip_list.index(ip_addr)
if ip_addr != and status[ip_row_index] != 'unavailable':
mme_at_ip = mme_name[ip_row_index]
result_list = (mrbts_id, key, mme_at_ip, ip_addr)
if result_list[0:2][::-1] not in src_mrbts_key:
src_mrbts_key.append(result_list[0:2])
source_list.append(result_list)
else:
target_list.append(result_list)
return source_list, target_list



Explanation:




I have an Excel spreadsheet:



MRBTS  IPs  NAMES STATUS
1234 IP1 N1 Yes
1234 IP2 - No
1234 IP3 N3 Yes
1236 IP1 N4 Yes
1236 IP4 N5 Yes
1238 IP3 N7 Yes
1238 IP4 N9 Yes
1238 IP5 - No



My Code will full fill these requirements:




1) I need to compare each MRBTS with each other just like



comp(1234,1236),comp(1234,1238),comp(1236,1234),comp(1236,1238),comp(1238,1234),comp(1238,1236),...] but not with same mrbts like comp(1234,1234).



2) Lets take (if status=Yes) for comp(1236,1238): In 1236's I have some list(IPs[IP1,IP4] and Ns[N4,N5]) so again i need to compare those list with 1238's list(IP[IP3,IP4] and Ns[N7,N9]) {Here we didn't considered IP5 as status = No}, if any IP in 1236(IP list) is not found in 1238(IP list) then return that IP,Name and only if status=Yes



compare(1236,1238) = [1236,IP1,N4] and compare(1238,1236) = [1238,IP3,N7]


3) Now do the comparison for all combis and get results and store like source = [compare(1236,1238)] and target = [compare(1238,1236)] Note: Here we can observe source has right ordered comparison and target has reverse ordered comparison.




Now I want, help to make above code efficient and less the time complexity:




Note:



i. Avoid Nested for loops as my Original excel has a huge number of data it'll take time to read, else if u use then make execution fast.



ii. Use openpyxl or pyxlsb packages only







python excel python-3.x list-comprehension openpyxl






share|improve this question







New contributor




Deepika is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Deepika is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Deepika is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 21 at 5:16









Deepika

12




12




New contributor




Deepika is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Deepika is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Deepika is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




closed as off-topic by stovfl, DanielBarbarian, Charlie Clark, Unheilig, greg-449 Nov 21 at 11:55



  • This question does not appear to be about programming within the scope defined in the help center.

If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by stovfl, DanielBarbarian, Charlie Clark, Unheilig, greg-449 Nov 21 at 11:55



  • This question does not appear to be about programming within the scope defined in the help center.

If this question can be reworded to fit the rules in the help center, please edit the question.












  • I think you should add post in codereview.stackexchange.com
    – mehrdad-pedramfar
    Nov 21 at 6:17












  • @mehrdad-pedramfar What makes the difference?
    – Deepika
    Nov 21 at 6:19










  • That community is built for your problem Code Review.
    – mehrdad-pedramfar
    Nov 21 at 6:20






  • 1




    ok, thank you I'll post there
    – Deepika
    Nov 21 at 6:22






  • 2




    I'm voting to close this question as off-topic because should be moved to codereview.stackexchange.com
    – stovfl
    Nov 21 at 7:35


















  • I think you should add post in codereview.stackexchange.com
    – mehrdad-pedramfar
    Nov 21 at 6:17












  • @mehrdad-pedramfar What makes the difference?
    – Deepika
    Nov 21 at 6:19










  • That community is built for your problem Code Review.
    – mehrdad-pedramfar
    Nov 21 at 6:20






  • 1




    ok, thank you I'll post there
    – Deepika
    Nov 21 at 6:22






  • 2




    I'm voting to close this question as off-topic because should be moved to codereview.stackexchange.com
    – stovfl
    Nov 21 at 7:35
















I think you should add post in codereview.stackexchange.com
– mehrdad-pedramfar
Nov 21 at 6:17






I think you should add post in codereview.stackexchange.com
– mehrdad-pedramfar
Nov 21 at 6:17














@mehrdad-pedramfar What makes the difference?
– Deepika
Nov 21 at 6:19




@mehrdad-pedramfar What makes the difference?
– Deepika
Nov 21 at 6:19












That community is built for your problem Code Review.
– mehrdad-pedramfar
Nov 21 at 6:20




That community is built for your problem Code Review.
– mehrdad-pedramfar
Nov 21 at 6:20




1




1




ok, thank you I'll post there
– Deepika
Nov 21 at 6:22




ok, thank you I'll post there
– Deepika
Nov 21 at 6:22




2




2




I'm voting to close this question as off-topic because should be moved to codereview.stackexchange.com
– stovfl
Nov 21 at 7:35




I'm voting to close this question as off-topic because should be moved to codereview.stackexchange.com
– stovfl
Nov 21 at 7:35

















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...