@Rushpil

Оптимизировать программу?

Дан текстовый файл : https://github.com/taolin204/algorithm/blob/master... . Нужно вывести список смежности актеров. Например:
Ввод:
Brown, Bryan (I)
Вывод:
{'Fraser, Helen (I)', 'Lloyd, Yolanda', 'Brand, Gibby', 'Vargas, Gustavo (I)', 'Louis, Justin (I)', 'Lavelle, Susanne', 'Peterson, Ron', 'Venora, Diane', 'Mbandu, Konga', 'Fitz-Gerald, Lewis', 'Butel, Mitchell', 'Tenorio Gonzales, Claudia', 'Bennett, Grant (I)', 'Sheaves, Evan', 'Reynolds, Michael J.', 'Ramos Nishita, Mark', 'Smith, Chris (I)', 'Hines, Cheryl', 'Doumanian, John', 'Benevento, Nicholas', 'Coco, Salvatore', 'Espinosa, Jose', 'Paramore, Kiri', 'Dishy, Bob', 'Garcia, Jsu', 'Alexander, John (II)', 'Long, Tom (I)', 'Balmaseda, George', 'Skyler, Robb', 'Wachira, Waigwa', "Morgan, Walter 'Crash'", 'Mainprize, James', 'Ash, Adrienne', 'Shue, Elisabeth', 'Nozick, Bruce', 'Beck, Marvin', 'Shapiro, Theodore', 'Messing, Debra', 'Pyle, Missi', 'Boyden, Peter', "Duggan, Hal 'Saint'", 'Koch, Robert M.', 'Elliott, Jim (I)', 'Procanin, Michael', 'Gehman, Martha', 'Innes, Mick', 'Monk, Damian', 'Duckworth, Rob', 'Le Marquand, Steve', 'Bradford, Damian', 'Zaccone, Joseph', 'Baldwin, Alec', 'Alexandrov, Constantin', 'Silverman, Jeff (I)', 'Sherrard, Jeffrey', 'Kirk, Christina', 'Thompson, Jack (I)', 'Gershon, Gina', 'Saunders, Lew', 'Connell, Kelly', 'Miranda, Walter (I)', 'Ball, Vincent (I)', 'Shamberg, Michael (I)', 'Fenton, Stuart', 'Orman, Roscoe', 'Whitley, Kym', 'Pickens Jr., James', 'Drury, William (I)', 'Oka, Masi', 'Stashwick, Todd', 'Dean, Nathan', 'Crowley, Ed (I)', 'Reed, Maria', 'Crowley, David L.', 'Abbott, Paul (I)', 'Campbell, Gerald', 'Cisse, Halifa', 'Bateman, Bill (I)', 'Zissler, Jonno', 'Carradine, Sandra Will', 'Woodward, Edward', 'Waters, John (III)', 'Baron, Rabbi David', 'Mclean, Peter', 'Wilkinson, Mathew', 'Spence, Stuart', 'Stiller, Ben', 'Morse, Andrea', 'Noonan, Tom', 'Endo, Mari', 'Wong, Michael (V)', 'Mazerolle, Arlene', 'Quin, Don', 'Dean, Ron (I)', 'Meagher, Ray', 'Harris, Marykate', 'Radford, Elspeth', 'Cornish, Bridget', 'Willgrubs, Richard', 'Zalez, Rudy', 'Luckinbill, Laurence', 'Heatherington, Dianne', 'Graham, John (V)', 'Broeker, Jaap', 'Elliott, Peter (II)', 'Eckhouse, James', "Jongs, Monique 'Nikki'", 'Ortiz, Alfredo (I)', 'Jameson, Nick', 'Nicholls, Jon', 'Walls, Allen', 'Lynch, Kelly (I)', 'Shue, Andrew', "Sinclair, Charles 'Tower'", 'Douglass, Diane', 'Porter, Susie', 'McLoughlin, John (I)', 'Cordes, Jim', 'Hayes, Richard (II)', 'Smith, Kevin (XXXII)', 'Mullinar, Rod', 'Bachar, Carmit', 'Glen, Iain', 'Steele, Rob (I)', 'Blazeak, Paul', 'Furfaro, Adam', 'Moeaki, David', 'Foley, Ellen', 'DuMont, James', 'Erskine, Drummond', 'Amodeo, Daniel', 'Hernández, Gustavo', 'De Young, Cliff', 'Natalie, Lisa', 'Sari, Waddah', 'Lee, Michele (I)', 'Pfitzner, John', 'Pentangelo, Joe', 'Byrne, Rose', 'Mitchell, Chris (IV)', 'Wallace, Brian W.', 'Wilson, Trey', 'Owens, Chris (I)', 'Hart, Kevin (I)', 'Currer, Norman', 'Palermo, Vivian', 'Haywood, Chris (I)', 'Kalnins, Dale', 'Fujimoto, Mike', 'Ledger, Heath', 'Bernard, Hank', 'Adams, Mason', 'Ross, Cali', 'Knez, Bruno', 'West, Barbara', 'Bassett, Angela', 'Darcy-Smith, Kieran', 'Yeates, Haile', 'Erskine, Ria', 'Aniston, Jennifer', 'Horseman, Sylvia', 'Conna, Edward', 'Ehlers, Jerome', 'Ball, Ray (I)', 'Ross, Jeffrey (I)', 'Lansbury, David', 'Hunter, Ronald (I)', 'St. James, Jean', 'Forrow, Tony', 'Marshall, Rosalyn', 'Barron, Richard (IV)', 'Kemp, Jai', 'King, Anthony (III)', 'Kiefel, Russell', 'Benedict, Paul', 'Seidel, Nellie', 'Cruise, Tom', 'Repo-Martell, Liisa', 'Stanley, Kristine', 'Silpa, Mitch', 'Adair-Rios, Mark', 'Azaria, Hank', 'De Baer, Jean', 'Nelles, Kim', 'Ranelin, Phillip', 'Nduati, Peter', 'Harris, Julie (I)', 'Sperdakos, George', 'Tamras, Ator', 'Care, Eugenia', 'Beagle, E. Hampton', 'Darling, Jarrah', 'Cuthbertson, Iain', 'Suter, Glen', 'Lovett, Alan', 'Acres, Mary', 'Bamman, Gerry', 'McHale, Christopher', 'Livingston, Richard (I)', 'Hunter, Andrew (I)', 'Assad, Richard', 'Rodger, Ron', 'Bell, Wayne (I)', 'Donley, Robert', 'Thorn, Richard (I)', 'Kodisch, George', 'Corcoran, Imelda', 'Osborn, Peter', 'Weaver, Sigourney', 'Drayton, Leslie', 'Babchak, Jim', 'De La Cruz, Marco', 'Cross, Ryan (I)', 'Hoffman, Philip Seymour', 'Grifasi, Joe', 'Maguire, Ellen', 'Iannicelli, Ray', 'Wright, Tim (III)', 'Donovan, Terence (I)', 'Barger, Christine', 'Walton, Laurie (I)', 'Savakkis, Poppy', 'Friedman, Bernie', 'Phillips, Jacquy', 'Staunton, Brian', 'Pastore, Garry', 'Dick, Judy', 'Crater, Rich', 'Whitman, Parker', 'Dennehy, Brian', "O'Neill, Maggie (I)", 'Masten, Gordon', 'Baker, Gregg (I)', "D'Amato, Paul (I)", 'DeGuzman, Jossie', 'Miluwi, John Omirah', 'Vidler, Steven', 'Gallin, Tim', 'Block, Larry (I)', 'McGregor, Ken (I)', 'Jones, Lynden', 'Gibbons, Leroy', 'Orbach, Jerry', 'Wain, David', 'Wynne, Avril', 'Henderson, Dick (II)', 'Neilly, Vernon', 'Hernandez, Gustavo', 'Cassell, Alan (I)', 'Wilson, Frank (II)', 'Bean, Reathel', 'McClorey, Mariel', 'Parrott, Tomasina', 'Fischetti, Michael', 'Cheshire, Denise', "Dowd, M'el", "O'Sullivan, Moya", "Harvey, Rupert 'Ojiji'", 'St. Michael, Jody', 'Webb, Jim (II)', 'Gray, Ian (I)', 'Blair, Toni', 'Greenberg, Robert (II)', "Walsh, Eric 'Babyface'", 'Mann, Trevor (I)', 'Silverstein, Stuart', "Tingwell, Charles 'Bud'", 'Friedlander, Judah', 'Marriott, Anjulie', 'Lovelett, Jim', 'Faulk, Alison', 'Hoyos, Antonio', 'Field, David (I)', 'Hansraj, Luther', 'Curry, Christopher (I)', 'Young, Warwick', 'Banes, Lisa', 'Praed, Brett', 'Chant, David', 'Newman, Jack (II)', 'Tarnawski, Katya', 'Stack, Patrick', 'Hohn, Amy', 'Wasserman, Allan', 'Aaron, Caroline', 'Muncu, Adam', 'Alperin, Harvey J.'}

Вот сам код:
act = dict()
with open(r"C:\Users\Максим\films\movies.txt", encoding='utf-8') as file:
    for l in file:
        s = l.strip().split("/")[1:]
        n = len(s)
        for i in range(n):
            if s[i % n] in act:
                act[s[i % n]].update({s[(j + i) % n] for j in range(1, n)})
            else:
                act[s[i % n]] = {s[(j + i) % n] for j in range(1, n)}
print(act['имя актера'])

P.S. один и тот же актер может сниматься в нескольких фильмах.
Как можно оптимизировать создание списка смежности или поиска актеров снимавшихся с указанным актером,поскольку программа не проходит по памяти ?
  • Вопрос задан
  • 158 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы