list

Comparing two lists and returning the difference

丶灬走出姿态 提交于 2021-02-15 07:44:57
问题 I've got two lists of lists, I match them and print any differences. The two lists are cable connections within a FPGA station. I need to ensure: All the connections on the $list1 exist on $list2 , if not, it should save the error on another list All the connections on $list2 exist on $list1 , so I don't get any 'wrong' connections. Any connections that don't exist on either list should be saved onto another variable. The lists are in this format: {{A.B2} {B.B3}} and the the $list2 equivalent

Comparing two lists and returning the difference

我只是一个虾纸丫 提交于 2021-02-15 07:43:43
问题 I've got two lists of lists, I match them and print any differences. The two lists are cable connections within a FPGA station. I need to ensure: All the connections on the $list1 exist on $list2 , if not, it should save the error on another list All the connections on $list2 exist on $list1 , so I don't get any 'wrong' connections. Any connections that don't exist on either list should be saved onto another variable. The lists are in this format: {{A.B2} {B.B3}} and the the $list2 equivalent

How to not lose a data from the list when going from one screen to another screen in flutter?

时间秒杀一切 提交于 2021-02-15 06:56:08
问题 I have a class ViewTotalItemProvider which extends the ChangeNotifier. Inside the class, there is a list like this. class ViewTotalItemProvider extends ChangeNotifier{ List<CartPlantLists> cartPlantList3 = []; } Additionally, there are 3 screens including class like, PlantFeatureScreen1 , ParticularPlant2 , CartDetais3 . All are stateful widget and I am adding some items in second screen i.e. ParticularPlant2 class. When I try to show the items from list in the second screen and the third

How to create a binary list based on inclusion of list elements in another list

别说谁变了你拦得住时间么 提交于 2021-02-15 05:38:12
问题 Given two lists of words, dictionary and sentence , I'm trying to create a binary representation based on the inclusion of words of dictionary in the sentence such as [1,0,0,0,0,0,1,...,0] where 1 indicates that the ith word in the dictionary shows up in the sentence. What's the fastest way I can do this? Example data: dictionary = ['aardvark', 'apple','eat','I','like','maize','man','to','zebra', 'zed'] sentence = ['I', 'like', 'to', 'eat', 'apples'] result = [0,0,1,1,1,0,0,1,0,0] Is there

Using a dict to translate numbers to letters in python

独自空忆成欢 提交于 2021-02-13 17:40:22
问题 I have a string 'alphabet' with all the letters in the alphabet and a list of ints corresponding to those those letters (0-25). Ex: num_list = [5,3,1] would translate into letter_list = ['f','d','b'] I currently can translate with: letter_list = [alphabet[a] for a in num_list] However, I would like to use a dict for the same thing, retrieve 'letter' keys from dict with 'number' values. alpha_dict = {'a':0,'b':1,'c':2}... etc How do I change my statement to do this? 回答1: Simply iterate through

Using a dict to translate numbers to letters in python

三世轮回 提交于 2021-02-13 17:38:18
问题 I have a string 'alphabet' with all the letters in the alphabet and a list of ints corresponding to those those letters (0-25). Ex: num_list = [5,3,1] would translate into letter_list = ['f','d','b'] I currently can translate with: letter_list = [alphabet[a] for a in num_list] However, I would like to use a dict for the same thing, retrieve 'letter' keys from dict with 'number' values. alpha_dict = {'a':0,'b':1,'c':2}... etc How do I change my statement to do this? 回答1: Simply iterate through

Using a dict to translate numbers to letters in python

自古美人都是妖i 提交于 2021-02-13 17:37:34
问题 I have a string 'alphabet' with all the letters in the alphabet and a list of ints corresponding to those those letters (0-25). Ex: num_list = [5,3,1] would translate into letter_list = ['f','d','b'] I currently can translate with: letter_list = [alphabet[a] for a in num_list] However, I would like to use a dict for the same thing, retrieve 'letter' keys from dict with 'number' values. alpha_dict = {'a':0,'b':1,'c':2}... etc How do I change my statement to do this? 回答1: Simply iterate through

How to fix .index() method returning the wrong value?

早过忘川 提交于 2021-02-13 17:35:15
问题 I'm trying to get the index of the values higher than 70 from the following list: temperatures = [33, 66, 65, 62, 59, 60, 62, 64, 70, 76, 80, 69, 80, 83, 68, 79, 61, 53, 50, 49, 53, 48, 45, 39] But something is going wrong when the loop finds equal values: hour_ex = [] for i in temperatures: if i > 70: hour_ex.append(temperatures.index(i)) print(hour_ex) The code above is printing: [9, 10, 10, 13, 15] When the loop reach the index 12, it prints again the index 10 because it has the same value

How to fix .index() method returning the wrong value?

不羁的心 提交于 2021-02-13 17:34:07
问题 I'm trying to get the index of the values higher than 70 from the following list: temperatures = [33, 66, 65, 62, 59, 60, 62, 64, 70, 76, 80, 69, 80, 83, 68, 79, 61, 53, 50, 49, 53, 48, 45, 39] But something is going wrong when the loop finds equal values: hour_ex = [] for i in temperatures: if i > 70: hour_ex.append(temperatures.index(i)) print(hour_ex) The code above is printing: [9, 10, 10, 13, 15] When the loop reach the index 12, it prints again the index 10 because it has the same value

IndexError: string index out of range:

此生再无相见时 提交于 2021-02-13 17:32:27
问题 I'm trying take a .txt file populated by 88 rows, each of which has two characters separated by a space, copy the first character in each row into a list #1, copy the second character of each list into a list #2 and then populate a dictionary with those two lists. Something, however, is going wrong when I try to copy down the data from the file into my lists. Could you tell me what I'm not doing correctly? I keep getting this error: "IndexError: string index out of range" at the line where I