Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #108666 > unrolled thread
| Started by | DFS <nospam@dfs.com> |
|---|---|
| First post | 2016-05-16 10:54 -0400 |
| Last post | 2016-05-16 16:50 -0400 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.python
A tough one: split on word length? DFS <nospam@dfs.com> - 2016-05-16 10:54 -0400
Re: A tough one: split on word length? Laurent Pointal <laurent.pointal@free.fr> - 2016-05-16 19:13 +0200
Re: A tough one: split on word length? DFS <nospam@dfs.com> - 2016-05-16 16:29 -0400
Re: A tough one: split on word length? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-05-16 20:27 +0100
Re: A tough one: split on word length? DFS <nospam@dfs.com> - 2016-05-16 16:50 -0400
| From | DFS <nospam@dfs.com> |
|---|---|
| Date | 2016-05-16 10:54 -0400 |
| Subject | A tough one: split on word length? |
| Message-ID | <nhcmpg$gi6$1@dont-email.me> |
Have:
'584323 Fri 13 May 2016 17:37:01 -0000 (UTC) 584324 Fri 13 May 2016
13:44:40 -0400 584325 13 May 2016 17:45:25 GMT 584326 Fri 13 May 2016
13:47:28 -0400'
Want:
[('584323', 'Fri 13 May 2016 17:37:01 -0000 (UTC)'),
('584324', 'Fri 13 May 2016 13:44:40 -0400'),
('584325', '13 May 2016 17:45:25 GMT'),
('584326', 'Fri 13 May 2016 13:47:28 -0400')]
Or maybe split() on space, then run through and add words of 6+ numbers
to the list, then recombine everything until you hit the next group of
6+ numbers, and so on?
The data is guaranteed to contain those 6+ groups of numbers.
[toc] | [next] | [standalone]
| From | Laurent Pointal <laurent.pointal@free.fr> |
|---|---|
| Date | 2016-05-16 19:13 +0200 |
| Message-ID | <5739ffbf$0$26281$426a74cc@news.free.fr> |
| In reply to | #108666 |
DFS wrote:
> Have:
> '584323 Fri 13 May 2016 17:37:01 -0000 (UTC) 584324 Fri 13 May 2016
> 13:44:40 -0400 584325 13 May 2016 17:45:25 GMT 584326 Fri 13 May 2016
> 13:47:28 -0400'
>
> Want:
> [('584323', 'Fri 13 May 2016 17:37:01 -0000 (UTC)'),
> ('584324', 'Fri 13 May 2016 13:44:40 -0400'),
> ('584325', '13 May 2016 17:45:25 GMT'),
> ('584326', 'Fri 13 May 2016 13:47:28 -0400')]
>
>
> Or maybe split() on space, then run through and add words of 6+ numbers
> to the list, then recombine everything until you hit the next group of
> 6+ numbers, and so on?
>
> The data is guaranteed to contain those 6+ groups of numbers.
Test with regexp under Python3
>>> import re
>>> s = '584323 Fri 13 May 2016 17:37:01 -0000 (UTC) 584324 Fri 13 May 2016
13:44:40 -0400 584325 13 May 2016 17:45:25 GMT 584326 Fri 13 May 2016
13:47:28 -0400'
>>> re.split("(\d{6})(.*?)", s)
['', '584323', '', ' Fri 13 May 2016 17:37:01 -0000 (UTC) ', '584324', '', '
Fri 13 May 2016 13:44:40 -0400 ', '584325', '', ' 13 May 2016 17:45:25 GMT
', '584326', '', ' Fri 13 May 2016 13:47:28 -0400']
Dismiss empty items and strip whitespaces at begin or end of string, and
that's done.
A+
Laurent.
Note: re experts will provide a cleaner solution.
[toc] | [prev] | [next] | [standalone]
| From | DFS <nospam@dfs.com> |
|---|---|
| Date | 2016-05-16 16:29 -0400 |
| Message-ID | <nhdacg$jg$1@dont-email.me> |
| In reply to | #108675 |
On 5/16/2016 1:13 PM, Laurent Pointal wrote:
> DFS wrote:
>
>> Have:
>> '584323 Fri 13 May 2016 17:37:01 -0000 (UTC) 584324 Fri 13 May 2016
>> 13:44:40 -0400 584325 13 May 2016 17:45:25 GMT 584326 Fri 13 May 2016
>> 13:47:28 -0400'
>>
>> Want:
>> [('584323', 'Fri 13 May 2016 17:37:01 -0000 (UTC)'),
>> ('584324', 'Fri 13 May 2016 13:44:40 -0400'),
>> ('584325', '13 May 2016 17:45:25 GMT'),
>> ('584326', 'Fri 13 May 2016 13:47:28 -0400')]
>>
>>
>> Or maybe split() on space, then run through and add words of 6+ numbers
>> to the list, then recombine everything until you hit the next group of
>> 6+ numbers, and so on?
>>
>> The data is guaranteed to contain those 6+ groups of numbers.
>
> Test with regexp under Python3
>
>>>> import re
>>>> s = '584323 Fri 13 May 2016 17:37:01 -0000 (UTC) 584324 Fri 13 May 2016
> 13:44:40 -0400 584325 13 May 2016 17:45:25 GMT 584326 Fri 13 May 2016
> 13:47:28 -0400'
>>>> re.split("(\d{6})(.*?)", s)
> ['', '584323', '', ' Fri 13 May 2016 17:37:01 -0000 (UTC) ', '584324', '', '
> Fri 13 May 2016 13:44:40 -0400 ', '584325', '', ' 13 May 2016 17:45:25 GMT
> ', '584326', '', ' Fri 13 May 2016 13:47:28 -0400']
>
>
> Dismiss empty items and strip whitespaces at begin or end of string, and
> that's done.
>
> A+
> Laurent.
> Note: re experts will provide a cleaner solution.
Thanks Laurent.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-05-16 20:27 +0100 |
| Message-ID | <87bn45ztv5.fsf@bsb.me.uk> |
| In reply to | #108666 |
DFS <nospam@dfs.com> writes:
> Have:
> '584323 Fri 13 May 2016 17:37:01 -0000 (UTC) 584324 Fri 13 May 2016
> 13:44:40 -0400 584325 13 May 2016 17:45:25 GMT 584326 Fri 13 May 2016
> 13:47:28 -0400'
>
> Want:
> [('584323', 'Fri 13 May 2016 17:37:01 -0000 (UTC)'),
> ('584324', 'Fri 13 May 2016 13:44:40 -0400'),
> ('584325', '13 May 2016 17:45:25 GMT'),
> ('584326', 'Fri 13 May 2016 13:47:28 -0400')]
[m for m in re.findall(r'(\d{6}) (.*?) ?(?:(?=\d{6})|$)', s)]
<snip>
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | DFS <nospam@dfs.com> |
|---|---|
| Date | 2016-05-16 16:50 -0400 |
| Message-ID | <nhdbkq$58d$1@dont-email.me> |
| In reply to | #108687 |
On 5/16/2016 3:27 PM, Ben Bacarisse wrote:
> DFS <nospam@dfs.com> writes:
>
>> Have:
>> '584323 Fri 13 May 2016 17:37:01 -0000 (UTC) 584324 Fri 13 May 2016
>> 13:44:40 -0400 584325 13 May 2016 17:45:25 GMT 584326 Fri 13 May 2016
>> 13:47:28 -0400'
>>
>> Want:
>> [('584323', 'Fri 13 May 2016 17:37:01 -0000 (UTC)'),
>> ('584324', 'Fri 13 May 2016 13:44:40 -0400'),
>> ('584325', '13 May 2016 17:45:25 GMT'),
>> ('584326', 'Fri 13 May 2016 13:47:28 -0400')]
>
> [m for m in re.findall(r'(\d{6}) (.*?) ?(?:(?=\d{6})|$)', s)]
>
> <snip>
Perfection. Thanks.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web