Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Select a part of an element of a list with Index
#1
I've created a list with a for loop and got elements with many elements... How can I make this easier?

    cmc = []

    CYC1 = cmc[0]

    CYC2 = cmc[1]

    CYC3 = cmc[2]

    CYC4 = cmc[3]

    c = []

    c.append(CYC1[67:79])

    c.append(CYC2[67:79])

    c.append(CYC3[67:79])

    print(c)
you don't need the intermediate cyc variables:
for i in range(4):
    c.append(cmc[i][67:79])
Larz60+ wrote Aug-09-2019, 11:15 AM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to find something in a list using its index rix 1 96 Dec-20-2019, 04:12 PM
Last Post: stullis
  item = index position - list of list RavCOder 9 248 Dec-02-2019, 05:24 PM
Last Post: ThomasL
  Why does pop() removes an element from more than one list? albufork 5 153 Nov-17-2019, 08:01 AM
Last Post: buran
  can't remove element from a list yokaso 6 186 Nov-06-2019, 03:11 PM
Last Post: yokaso
  get the one element from 1-list or 1-set Skaperen 1 104 Nov-05-2019, 11:50 PM
Last Post: Gribouillis
  IndexError: List index out of range issue Adem 1 468 Nov-01-2019, 10:47 PM
Last Post: ichabod801
  IndexError: list index out of range bug? CaptainCsaba 4 771 Oct-18-2019, 12:38 PM
Last Post: CaptainCsaba
  returns index of list if contains a word zarize 0 180 Sep-09-2019, 09:29 AM
Last Post: zarize
  MAWS.py PRGM:IndexError: list index out of range bcramer 0 189 Aug-28-2019, 04:45 PM
Last Post: bcramer
  List of dictionaries: use key-value instead of index? dn237 6 607 Jun-03-2019, 05:52 PM
Last Post: Yoriz

Forum Jump:


Users browsing this thread: 1 Guest(s)