如何在Python 2.7.1中将一串字母变成3个字母的单词
我有一串字母 'aaabbbcccdddeeefffggg
',我想将其读为 3 个字母的单词。例如,'aaa','bbb','ccc'...
您知道有任何代码可以执行此功能吗?
我的最终目标是为每个单词分配数字,例如
aaa= 123
bbb= 234
ccc= 356 ...
,并让输出为具有该值的单词在句子中的位置,
因此对于“aaabbbcccdddeeefffggg”的句子 三个字母的单词将是
'aaa','bbb','ccc'...
aaa
将是第一个位置 (1),bbb
code> 将是第二个位置 (2),ccc
将是第三个位置 (3)
所以最终我会得到
(1,123),(2,234),(3,356) for 'aaa','bbb','ccc'
我已经尝试了几个小时,但我不知道如何做到这一点所以任何帮助将不胜感激
谢谢
I have a string of letters 'aaabbbcccdddeeefffggg
' that i would like to read as 3 letter words. For example, 'aaa','bbb','ccc'...
Is there any code that you know of that can do this function?
My ultimate goal is to assign numbers to each word like
aaa= 123
bbb= 234
ccc= 356 ...
and have the output be the position of the word in the sentence with that value
so for the sentence of 'aaabbbcccdddeeefffggg
'
the three letter words would be 'aaa','bbb','ccc'...
aaa
would be the 1st position (1), bbb
would be the 2nd position (2), ccc
would be the 3rd position (3)
so ultimately i would get
(1,123),(2,234),(3,356) for 'aaa','bbb','ccc'
i have been trying this for a few hours and i cannot figure out how to do this so any help would be much appreciated
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
像这样的东西吗?
否则:
Something like this?
Otherwise:
或者
or