Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link list elements from 2nd to last element in Python

I am trying to extract the time and signal change from a .vcd file (Value change dump) in Python for analysis.

What I got:

# 100 (this is the timestamp)
['0', '#', '%']
['1', '@', '!']

What I hope to get:

# 100
['0', '#%']
['1', '@!']

This is my code:

import re
fname = input("Enter filename: ")
vcd = open(fname)

for line in vcd:
    line = line.rstrip()

    if re.findall('^#', line):
            time = line
            print(time)

    elif  re.findall('^0', line) or re.findall('^1', line):
            sigVar = list(line)
            for i in sigVar[1:]:
                    ''.join(sigVar)

            print(sigVar)

I couldn't join the elements in sigVar together. Any idea?

like image 233
moonplant Avatar asked Mar 15 '26 02:03

moonplant


1 Answers

You can try like this :

>>> l = ['1','2','3']
>>> l[1:] = [''.join(l[1:])]
>>> l
['1', '23']
like image 136
Harsha Biyani Avatar answered Mar 16 '26 14:03

Harsha Biyani