Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
index between values
#2
Here is a way, using module itertools
>>> import itertools as itt
>>> L = ['visit', 'houston', 'and', 'san', 'antonio', 'and', 'austin', 'and', 'corpus', 'christi']
>>> [list(g) for k, g in itt.groupby(L, key=lambda word: word=='and') if not k]
[['visit', 'houston'], ['san', 'antonio'], ['austin'], ['corpus', 'christi']]
Avoid using 'list' as a variable name, it is the name of a built-in function.
Reply


Messages In This Thread
index between values - by mapvis - Jan-03-2019, 04:28 AM
RE: index between values - by Gribouillis - Jan-03-2019, 09:06 AM
RE: index between values - by mapvis - Jan-03-2019, 07:04 PM
RE: index between values - by perfringo - Jan-04-2019, 11:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Function to return list of all the INDEX values of a defined ndarray? pjfarley3 2 1,992 Jul-10-2020, 04:51 AM
Last Post: pjfarley3
  Get all values of for loop with an index BollerwagenIng 2 2,528 Aug-09-2019, 07:58 AM
Last Post: BollerwagenIng

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020