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
  item = index position - list of list RavCOder 9 154 Dec-02-2019, 05:24 PM
Last Post: ThomasL
  Why does pop() removes an element from more than one list? albufork 5 130 Nov-17-2019, 08:01 AM
Last Post: buran
  can't remove element from a list yokaso 6 163 Nov-06-2019, 03:11 PM
Last Post: yokaso
  get the one element from 1-list or 1-set Skaperen 1 85 Nov-05-2019, 11:50 PM
Last Post: Gribouillis
  IndexError: List index out of range issue Adem 1 324 Nov-01-2019, 10:47 PM
Last Post: ichabod801
  IndexError: list index out of range bug? CaptainCsaba 4 318 Oct-18-2019, 12:38 PM
Last Post: CaptainCsaba
  returns index of list if contains a word zarize 0 150 Sep-09-2019, 09:29 AM
Last Post: zarize
  MAWS.py PRGM:IndexError: list index out of range bcramer 0 153 Aug-28-2019, 04:45 PM
Last Post: bcramer
  List of dictionaries: use key-value instead of index? dn237 6 573 Jun-03-2019, 05:52 PM
Last Post: Yoriz
  Preventing: IndexError: list index out of range PappaBear 1 2,531 Jun-03-2019, 05:50 PM
Last Post: SheeppOSU

Forum Jump:


Users browsing this thread: 1 Guest(s)