简体   繁体   中英

Trying to pull lines from a text file puting it into a list in python 3

I got it for the most part but when I put the unicode into a list the program does it letter by letter instead of as a whole. A single list full of the unicode was my goal.

with open('emoji-data.txt', 'rt') as in_file:
  for line in in_file:
    if ';' in line:
        uni = line[:4]
        s = line[6:11]
        second = (s.lstrip('.'))
        cleanuni = (uni.lstrip('# @m'))
        new = list(cleanuni)
        print(new)
  1. Start with an empty list before the loop: emoji = [] .

  2. Append each found word to the list: replace new = list(cleanuni) with emoji.append(cleanuni) .

  3. Move the print outside of the loop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM