back soft

مطالب مرتبط با «python list of strings» در back soft | نویسنده: استخدام کار

Python 3: How to read file json into list of dictionary?

Vote count: 0 I have file with Json format: {"uid": 2, "user": 1} {"uid": 2, "user": 1} {"uid": 2, "user": 1} When i use following code, it show an error: raise JSONDecodeError("Extra data", s, end) json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 22) with open('E:/list.txt','r') as target: my_list = json.load(target) How to convert content of my file into list of dictionary ? Thank you asked 28 secs agoNGuyen Let's block ads! بخوانید...

ادامه مطلب

Python list of lists filled with duplicate rows after writing each entry

Vote count: 0 I am iterating over each entry of a list of lists and filling it with some unique number but the final list of lists contains identical rows. Here's a MWE: x = [1,2,3,4] y = [3,6,9,12] Here I set up a list of lists filled with zeros. m = [[0]*len(x)]*len(y) And I print it to make sure it looks right. [print(i) for i in m] Now I iterate through each row and again through each item in the row and put the result of some calculation in each spot. for i,ii in enumerate(y): for j,jj in enumerate(x): m[i][j] = ii*jj But when I look at the final matrix it is just filled with repeated rows. Any help? [print(i) for i in m] asked 1 min agowrkyle Let's block ads! بخوانید...

ادامه مطلب

Python combine 2 lists of strings for CSV

Vote count: 0 I have two lists that I want to combine for csv output. alist = ['a', 'b', 'c'] blist = ['d', 'e', 'f'] However, I want the output for the csv to format like this: clist = ['a', 'b', 'c', 'd' 'e' 'f'] such that the last entry extended of the list contains the list of "blist", but will not be comma separated. Unfortunately, what I have been trying instead gives me: clist = ['a', 'b', 'c', 'def'] asked 1 min agoArca Let's block ads! بخوانید...

ادامه مطلب

Python List of Strings to Tuple Paris

Vote count: 0 I am having some difficulty coming up with an efficient way of taking a list of strings and converting it to tuple pairs. I have a list similar to: listOfNames = ['red-l','blue-l','green-s','red-s','blue-s'] Every color in this example (red, blue, and green) has either a '-l' or '-s' entry or both. I need to convert this list of strings into tuple pairs such as: tupleOfNames = [('red-l','red-s'),(None,'green-s'),('blue-l','blue-s')] I think regular expressions is needed but I am not sure how to do so. Any help is greatly appreciated. Thanks asked 32 secs agoBrendan This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone els...

ادامه مطلب

python: filter a nested list of strings with list comprehension

Vote count: 0 I am trying to use list comprehension to filter this list: inp = [['Fire 46.0.1', 'vlc 2.2.3','opt 0.9.9.10'], ['opt 0.9.9.11', 'notepad 6.9', 'adobe. 6.9', 'vlc 2.3.3']] into: out = [['Fire 46.0.1', 'vlc 2.2.3',], ['notepad 6.9', 'adobe. 6.9', 'vlc 2.3.3']] i.e. removing all the strings that start with opt. I am trying something like that: [soft for ls in inp if soft not soft.startswith('opt')] but something is wrong with the sintax.Any help? asked 2 mins agodiegus Let's block ads! بخوانید...

ادامه مطلب

برچسب‌های مرتبط

python 3 how to print on the same line | python 3 how to use pip | python 3 how to print | python 3 how to compare strings | python 3 how to print without newline | python 3 how to install modules | python 3 how to import module | python 3 how to open a file | python 3 how to run a script | python 3 how to convert bytes to string