Skip to content

Commit 36e3c31

Browse files
authored
Use deque.popleft() instead of list.pop(0) (nltk#3105)
1 parent 175929b commit 36e3c31

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

nltk/grammar.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"expanding" *lhs* to *rhs* in *tree*.
7070
"""
7171
import re
72+
from collections import deque
7273
from functools import total_ordering
7374

7475
from nltk.featstruct import SLASH, TYPE, FeatDict, FeatStruct, FeatStructReader
@@ -771,15 +772,15 @@ def remove_unitary_rules(cls, grammar):
771772
lexical
772773
"""
773774
result = []
774-
unitary = []
775+
unitary = deque([])
775776
for rule in grammar.productions():
776777
if len(rule) == 1 and rule.is_nonlexical():
777778
unitary.append(rule)
778779
else:
779780
result.append(rule)
780781

781782
while unitary:
782-
rule = unitary.pop(0)
783+
rule = unitary.popleft()
783784
for item in grammar.productions(lhs=rule.rhs()[0]):
784785
new_rule = Production(rule.lhs(), item.rhs())
785786
if len(new_rule) != 1 or new_rule.is_lexical():

0 commit comments

Comments
 (0)