Python Forum
slicing and indexing a list example
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
slicing and indexing a list example
#1
I have the following code:

s = "The quick brown fox jumps over the lazy dog."
words = s.split()
lengths = [[w.lower(), len(w)] for w in words]
for length in lengths:
 print(length)
The output is:

['the', 3]
['quick', 5]
['brown', 5]
['fox', 3]
['jumps', 5]
['over', 4]
etc.

I wish to change it to produce the lengths only, namely the numbers.
Also, is this an example of lists inside lists (nested lists)?
I am trying to
Reply


Messages In This Thread
slicing and indexing a list example - by leodavinci1990 - Oct-01-2020, 01:27 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Indexing problem while iterating list and subtracting lbtdne 2 2,147 May-14-2020, 10:19 PM
Last Post: deanhystad
  TypeError indexing a range of elements directly on the list JFerreira 2 2,225 Mar-30-2020, 04:22 PM
Last Post: bowlofred
  How to change 0 based indexing to 1 based indexing in python..?? Ruthra 2 4,363 Jan-22-2020, 05:13 PM
Last Post: Ruthra
  Help with slicing a list FWendeburg 3 2,611 Dec-02-2019, 04:57 PM
Last Post: michael1789
  "Up to but not including" (My personal guide on slicing & indexing) Drone4four 5 2,968 Nov-20-2019, 09:38 PM
Last Post: newbieAuggie2019
  List slicing issue Irhcsa 3 3,004 Apr-26-2019, 09:16 PM
Last Post: nilamo
  Slicing Python list of strings into individual characters Drone4four 5 3,551 Apr-17-2019, 07:22 AM
Last Post: perfringo
  String Slicing in List Comphrensions Patroclus72790 1 2,276 Mar-21-2019, 09:33 PM
Last Post: nilamo
  Slicing a complex dictionary and list Drone4four 2 6,786 Aug-16-2018, 02:27 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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