Python Forum
help to increment a third list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help to increment a third list
#1
Hi every one!

I'm really a beginner, so I hope this can be easy for you! I have a list named 'array' :
['B', '494', 'C', '495', '504', 'R', '505', '519', 'S', '519', 'B', '717', 'C', '718', '732', 'L', '733', '742', 'S', '742', 'B', '1008', 'C', '1009', 'R', '1018', '1033', 'S', '1033', 'B', '1236', 'C', '1237', '1242', 'R', '1243', '1261', 'S', '1261', 'B', '1502', 'C', '1503', '1511', 'R', '1512', '1526', 'C', '1527', '1527', 'S', '1527', 'B', '1720', 'C', '1721', '1728', 'R', '1729', '1745', 'S', '1745', 'B', '1941', 'C', '1942', '1951', 'R', '1952', '1966', 'S', '1966', 'B', '2172', 'C', '2173', '2178', 'R', '2179', '2197', 'S', '2197', 'B', '2400', 'R', '2401', '2419', 'C', '2420', 'L', '2421', '2425', 'S', '2425',
'B', '2618', 'R', '2619', '2625', 'C', '2626', '2635', 'R', '2636', '2643', 'S', '2643', 'B', '2846', 'C', '2847', '2854', 'R', '2855', '2864', 'C', '2865', '2865', 'L', '2866', '2871', 'S', '2871', 'B', '3074', 'C', '3075', '3080', 'R', '3081', '3092', 'C', '3093', '3093', 'L', '3094', '3099', 'S', '3099', 'B', '3304', 'C', '3305', '3312', 'R', '3313', '3329', 'S', '3329', 'B', '3530', 'C', '3531', '3537', 'R', '3538', '3548', 'C', '3549', '3555', 'S', '3555', 'B', '3750', 'C', '3751', '3757', 'R', '3758', '3767', 'C', '3768', '3768', 'L', '3769', '3775', 'S', '3775', 'B', '3984', 'C', '3985', '4008', 'R', '4009', '4009', 'S', '4009', 'B', '4234', 'C', '4235', '4241', 'R', '4242', '4252', 'C', '4253', '4253', 'L', '4257', '4259', 'S', '4259', 'B', '4472', 'C', '4473', '4482', 'L', '4483', '4497', 'S', '4497', 'B', '4720', 'C', '4721', '4730', 'L', '4731', '4745', 'S', '4745', 'B', '4962', 'C', '4963', '4986', 'R', '4987', '4987', 'S', '4987', 'B', '5202', 'C', '5203', '5211', 'R', '5212', '5227', 'S', '5227', 'B', '5434', 'C', '5435', '5442', 'S', '5459', 'B', '5658', 'C', '5659', '5666', 'R', '5667', '5683', 'S', '5683', 'B', '5890', 'C', '5891', '5903', 'C', '5904', '5905', 'S', '5905', 'E']

I need this list to become 3 different lists : 'cote' with the letters, 'time' with the first number after the letters, and 'away' with the 'time' numbers but with a lag (away[i] = time[i+1]. This I achieved. Except, when there is a second number in 'array' before the letter, i need this number to get in 'away'.

Here is what I have tried. # are trials that didn't work either. This code result in away[i] being time[i+1], without consideration for the second numbers in 'array'

a = open("essai.txt",'r')
content=a.read()
array=content.split()
b = len(array)
cote,time, away = [],[],[]
for i in range (b):
    if array[i]=='B' or array[i]=='C' or array[i]=='L' or array[i]=='R' or array[i]=='S' or array[i]=='E':
        cote.append(array[i])
    elif array[i-1]=='B' or array[i-1]=='C' or array[i-1]=='L' or array[i-1]=='R' or array[i-1]=='S' or array[i-1]=='E':
        time.append(array[i])
   # else :
       # away.append(array[i])
for i in range (1,len(time)-1):
    away.append(time[i])
#for i in range (b):
#    d=-1
#    if array[i]=='B' :
#        d+=1
#    elif array[i]!='B'and array[i]!='C'and array[i]!='L'and array[i]!='R'and array[i]!='S'and array[i]!='E' and array[i-1]!='B'and array[i-1]!='C'and array[i-1]!='L'and array[i-1]!='R'and array[i-1]!='S'and array[i-1]!='E':
#        away[d]=array[i]
for i in range (b):
    d=-1
    if array[i]=='B' or array[i]=='C' or array[i]=='L' or array[i]=='R' or array[i]=='S' or array[i]=='E':
        d+=1    
    elif array[i-1]=='B' or array[i-1]=='C' or array[i-1]=='L' or array[i-1]=='R' or array[i-1]=='S' or array[i-1]=='E':
        break
    else :
       away[d]=array[i]
print (cote,time,away)
sorry, here is my output
Output:
['B', 'C', 'R', 'S', 'B', 'C', 'L', 'S', 'B', 'C', 'R', 'S', 'B', 'C', 'R', 'S', 'B', 'C', 'R', 'C', 'S', 'B', 'C', 'R', 'S', 'B', 'C', 'R', 'S', 'B', 'C', 'R', 'S', 'B', 'R', 'C', 'L', 'S', 'B', 'R', 'C', 'R', 'S', 'B', 'C', 'R', 'C', 'L', 'S', 'B', 'C', 'R', 'C', 'L', 'S', 'B', 'C', 'R', 'S', 'B', 'C', 'R', 'C', 'S', 'B', 'C', 'R', 'C', 'L', 'S', 'B', 'C', 'R', 'S', 'B', 'C', 'R', 'C', 'L', 'S', 'B', 'C', 'L', 'S', 'B', 'C', 'L', 'S', 'B', 'C', 'R', 'S', 'B', 'C', 'R', 'S', 'B', 'C', 'S', 'B', 'C', 'R', 'S', 'B', 'C', 'C', 'S', 'E'] ['494', '495', '505', '519', '717', '718', '733', '742', '1008', '1009', '1018', '1033', '1236', '1237', '1243', '1261', '1502', '1503', '1512', '1527', '1527', '1720', '1721', '1729', '1745', '1941', '1942', '1952', '1966', '2172', '2173', '2179', '2197', '2400', '2401', '2420', '2421', '2425', '2618', '2619', '2626', '2636', '2643', '2846', '2847', '2855', '2865', '2866', '2871', '3074', '3075', '3081', '3093', '3094', '3099', '3304', '3305', '3313', '3329', '3530', '3531', '3538', '3549', '3555', '3750', '3751', '3758', '3768', '3769', '3775', '3984', '3985', '4009', '4009', '4234', '4235', '4242', '4253', '4257', '4259', '4472', '4473', '4483', '4497', '4720', '4721', '4731', '4745', '4962', '4963', '4987', '4987', '5202', '5203', '5212', '5227', '5434', '5435', '5459', '5658', '5659', '5667', '5683', '5890', '5891', '5904', '5905'] ['495', '505', '519', '717', '718', '733', '742', '1008', '1009', '1018', '1033', '1236', '1237', '1243', '1261', '1502', '1503', '1512', '1527', '1527', '1720', '1721', '1729', '1745', '1941', '1942', '1952', '1966', '2172', '2173', '2179', '2197', '2400', '2401', '2420', '2421', '2425', '2618', '2619', '2626', '2636', '2643', '2846', '2847', '2855', '2865', '2866', '2871', '3074', '3075', '3081', '3093', '3094', '3099', '3304', '3305', '3313', '3329', '3530', '3531', '3538', '3549', '3555', '3750', '3751', '3758', '3768', '3769', '3775', '3984', '3985', '4009', '4009', '4234', '4235', '4242', '4253', '4257', '4259', '4472', '4473', '4483', '4497', '4720', '4721', '4731', '4745', '4962', '4963', '4987', '4987', '5202', '5203', '5212', '5227', '5434', '5435', '5459', '5658', '5659', '5667', '5683', '5890', '5891', '5904']
Reply


Messages In This Thread
help to increment a third list - by hermine - Nov-29-2022, 10:14 AM
RE: help to increment a third list - by Gribouillis - Nov-29-2022, 11:01 AM
RE: help to increment a third list - by hermine - Nov-29-2022, 11:05 AM
RE: help to increment a third list - by Gribouillis - Nov-29-2022, 11:12 AM
RE: help to increment a third list - by hermine - Nov-29-2022, 11:41 AM
RE: help to increment a third list - by Larz60+ - Nov-29-2022, 02:26 PM
RE: help to increment a third list - by Gribouillis - Nov-29-2022, 03:00 PM
RE: help to increment a third list - by perfringo - Nov-29-2022, 04:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  mysql id auto increment not working tantony 10 2,675 Oct-18-2022, 11:43 PM
Last Post: Pedroski55
  Character Increment AnokhiRaaz 1 2,548 Apr-22-2021, 04:29 AM
Last Post: buran
  Increment text files output and limit contains Kaminsky 1 3,320 Jan-30-2021, 06:58 PM
Last Post: bowlofred
  Increment formula Kristenl2784 4 3,003 Jul-20-2020, 10:14 PM
Last Post: Kristenl2784
  [openpyxl] Increment cells being pasted into Template Kristenl2784 4 3,710 Jul-16-2020, 10:00 PM
Last Post: Kristenl2784
  How can I increment a List item with in a "for in" msteffes 4 3,664 Aug-14-2019, 08:55 AM
Last Post: DeaD_EyE
  How define iteration interval increment SriMekala 5 4,525 Jun-01-2019, 01:06 PM
Last Post: ichabod801
  SQlite3 quickly increment INT value? jmair 1 2,515 Mar-04-2019, 08:03 PM
Last Post: stranac
  increment variable in while loop Naito 3 3,079 Jan-20-2019, 12:30 PM
Last Post: Naito
  auto increment ambush 7 14,720 Nov-02-2018, 10:52 PM
Last Post: LeSchakal

Forum Jump:

User Panel Messages

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