TransWikia.com

Printing wrong text in list in Python

Stack Overflow Asked by N1NG4 on December 13, 2021

This is My Code.

import requests as req
from bs4 import BeautifulSoup
page = req.get('https://www.compart.com/en/unicode/block/U+0900')
soup = BeautifulSoup(page.content, 'html.parser')
myunicode = soup.select('.uid')
myunicodes = [myunicodes.text for myunicodes in myunicode]
res = [sub.replace('+', 'u') for sub in myunicodes]
res = [sub.replace('U', '') for sub in res]
list = ['\' + item for item in res]
print(list)

When I am trying to add backslash in the list of strings with the following code.
list = ['\' + item for item in res] This Will remove + From the list and add ‘\’ in the starting of the code. I am also tried with r'\' But this is not worked for me. Please Help me to Solvee this. Here is What I got.

['\u0900', '\u0901', '\u0902', '\u0903', '\u0904', '\u0905', '\u0906', '\u0907', '\u0908', '\u0909', '\u090A', '\u090B', '\u090C', '\u090D', '\u090E', '\u090F', '\u0910', '\u0911', '\u0912', '\u0913', '\u0914', '\u0915', '\u0916', '\u0917', '\u0918', '\u0919', '\u091A', '\u091B', '\u091C', '\u091D', '\u091E', '\u091F', '\u0920', '\u0921', '\u0922', '\u0923', '\u0924', '\u0925', '\u0926', '\u0927', '\u0928', '\u0929', '\u092A', '\u092B', '\u092C', '\u092D', '\u092E', '\u092F', '\u0930', '\u0931', '\u0932', '\u0933', '\u0934', '\u0935', '\u0936', '\u0937', '\u0938', '\u0939', '\u093A', '\u093B', '\u093C', '\u093D', '\u093E', '\u093F', '\u0940', '\u0941', '\u0942', '\u0943', '\u0944', '\u0945', '\u0946', '\u0947', '\u0948', '\u0949', '\u094A', '\u094B', '\u094C', '\u094D', '\u094E', '\u094F', '\u0950', '\u0951', '\u0952', '\u0953', '\u0954', '\u0955', '\u0956', '\u0957', '\u0958', '\u0959', '\u095A', '\u095B', '\u095C', '\u095D', '\u095E', '\u095F', '\u0960', '\u0961', '\u0962', '\u0963', '\u0964', '\u0965', '\u0966', '\u0967', '\u0968', '\u0969', '\u096A', '\u096B', '\u096C', '\u096D', '\u096E', '\u096F', '\u0970', '\u0971', '\u0972', '\u0973', '\u0974', '\u0975', '\u0976', '\u0977', '\u0978', '\u0979', '\u097A', '\u097B', '\u097C', '\u097D', '\u097E', '\u097F']

Here What is Expected .

# Need All the Strings Like the Following
['u097E', 'u097F',] # Need All the Codes...

Thanks For Your Help in Advance ! ❤️

One Answer

Your code is as i should be:

import requests as req
from bs4 import BeautifulSoup
page = req.get('https://www.compart.com/en/unicode/block/U+0900')
soup = BeautifulSoup(page.content, 'html.parser')
myunicode = soup.select('.uid')
myunicodes = [myunicodes.text for myunicodes in myunicode]
res = [sub.replace('+', 'u') for sub in myunicodes]
res = [sub.replace('U', '') for sub in res]
list = ['\' + item for item in res]
for l in list:
    print(l)

Outputs:

u0900
u0901
u0902
u0903
u0904
u0905
u0906

Answered by UWTD TV on December 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP