Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一直有个疑惑:jieba中的lcut()方法中的“l”代表什么意思? #1000

Closed
paradise321 opened this issue Sep 12, 2023 · 3 comments

Comments

@paradise321
Copy link

看代码也没能看明白,是取自指从左到右的“Left”吗?谢谢!

@LyuLumos
Copy link

LyuLumos commented Sep 12, 2023

The l in lcut() means list.

jieba.lcut() returns a list, while jieba.cut() returns a generator. You can run following code.

import jieba

text = "我喜欢使用jieba进行中文分词"
result_cut = jieba.cut(text)
result_lcut = jieba.lcut(text)

print(type(result_cut), type(result_lcut))

print(list(result_cut), result_lcut)

Output:

<class 'generator'> <class 'list'>
['我', '喜欢', '使用', 'jieba', '进行', '中文', '分词']['我', '喜欢', '使用', 'jieba', '进行', '中文', '分词']

Also, you can find this in source code:

def lcut(self, *args, **kwargs):
    return list(self.cut(*args, **kwargs))

@paradise321
Copy link
Author

Thanks!

@manother
Copy link

manother commented May 22, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants