Posts

Showing posts with the label list

How can i use ' ++ i ' inside this situation?

Image
Clash Royale CLAN TAG #URR8PPP How can i use ' ++ i ' inside this situation? I want to draw a random name for an event where users can win items specified by their ID (1,2,3 etc.). The random name part is ok by now but how can i display the result like: The ID : 1 winner is: 'the random name' The ID : 2 winner is: 'the random name' etc... till ID : 27 static void Main(string args) { string Names = { "Erik", "Levente", "Noel", "Áron", "Krisztián", "Kristóf", "Bence", "Roland", "Máté", "László", "Bálint" , "Regina", "Brigitta", "Gréta", "Hédi", "Hanna", "Boglárka", "Jázmin", "Réka", "Alexandra", "Rebeka", "Lili", "Luca", "Zsófi"}; List<string> alreadyUsed = new List<string>(); Ra...

Read all words from a given text file and print a count for each

Image
Clash Royale CLAN TAG #URR8PPP Read all words from a given text file and print a count for each Test.txt contains the following sentence(How much wood would a woodchuck chuck if a woodchuck could chuck wood.) This program is supposed to read all words from a given text file (until eof) and print out a count for each word. The word should be processed case-insensitive (all capitals), punctuation should be removed and the output should be sorted by frequency. However I've come to a simple problem where it's counting lines and not the words, help a brother out. Make a translation table for getting rid of non-word characters dropChars = "!@#$%ˆ& ()_+-={}|\:;"’<>,.?/1234567890" dropDict = dict([(c, '') for c in dropChars]) dropTable = str.maketrans(dropDict) Read a file and build the table. f = open("Test.txt") testList=list() lineNum = 0 table = {} # dictionary: words -> set of line numbers for line in f: testList.append(line) for ...

How to match substring in a string using Python [duplicate]

Image
Clash Royale CLAN TAG #URR8PPP How to match substring in a string using Python [duplicate] This question already has an answer here: I have a list of substrings that I have to match in a string iteratively; if matching then perform the desired functionality. The problem is that, whenever I tried to access the list with loops it does not work. Otherwise if I hard code it then it works. I do not understand why it is so? My code is here: players_list = ['Circket', 'PSL', 'IPL', 't20', 'shahid afridi', 'aamer yamin'] length = len(players_list) cur.execute("SELECT tweet FROM tweets_data") # Query for getting specific attribute length = len(players_list) for row in cur.fetchall(): i = 0 while (i<length): #print players_list[i], 'tweet value', row if players_list[i] in row: print 'list item:', players_list[i] print row else: print 'Else statemen...

List in List Comparison in Python

Image
Clash Royale CLAN TAG #URR8PPP List in List Comparison in Python I have 2 list which are again inside a list .want to compare and get the difference . The first list of A need be compared with the first list of B and so on. a = [[' sh run vlan 1770', '', '', '', '!Command: show running-config vlan 1770', '!Time: Sun Jul 29 10:21:42 2018', '', 'version 7.1(4)N1(1c)', 'vlan configuration 1770', 'vlan 1770', ' name Finance', ' mode VPC', '', '', 'TEST1# ', '', '', 'TEST1#'], [' sh run vlan 1777', '', '', '', '!Command: show running-config vlan 1777', '!Time: Sun Jul 29 10:21:43 2018', '', 'version 7.1(4)N1(1c)', 'vlan configuration 1777', 'vlan 1777', ' name HR', ' mode VPC', '', '', 'TEST1# ', '', '', 'TE...

Remove Only One Item from a List (Android)

Image
Clash Royale CLAN TAG #URR8PPP Remove Only One Item from a List (Android) I have a list: (x, y, y,z) (x, y, y,z) I have another list: (x, y) (x, y) You want to remove the items from the 1st list that belong also in the 2nd list. Ex: I want the result to be (y,z) (y,z) How do I do this? EDIT: If I use removeAll. The example list returns (z) You want to remove the items from the 1st list that belong also in the 2nd list. Edit your question. – mTak 7 mins ago Does order matter? For example, if the second list was (y, x) would you want the same outcome? – Tyler V 4 mins ago The result will be (z) not (y,z) – mTak 3 mins ago ...

python lxml loop on match get next entry

Image
Clash Royale CLAN TAG #URR8PPP python lxml loop on match get next entry I'm using LXML to query multiple XML files containing data elements on various products. This section of code is taking a list of missing product_ids and querying the XML files for the data elements for the products. One of my core issues is that every product_id obtained through xpath is checked against every item in the list products_missing_from_postgresql , which takes forever (hours) How do I restart the for entry in entries loop when a match is found? Maybe this isn't the right question...if not what is the right question? for product_number in products_missing_from_postgresql: try: for entry in entries: product_id = entry.xpath('@id')[0] if product_id != product_number: print('************************') print('current product: ' + product_id) print('no match: ' + product_number) print('*********...

Simultaneously sum two keys in list of dicts by multiple items

Image
Clash Royale CLAN TAG #URR8PPP Simultaneously sum two keys in list of dicts by multiple items I want to sum two different variables in one function, but I want these to be summed based on multiple other items. If I have the following list of dicts x: x=[{'id':1, 'var1':'a', 'var2':'left', 'var3':0.1, 'var4':1}, {'id':2, 'var1':'a', 'var2':'right', 'var3':0.1, 'var4':1}, {'id':2, 'var1':'a', 'var2':'right', 'var3':0.2, 'var4':3}, {'id':4, 'var1':'b', 'var2':'left', 'var3':0.4, 'var4':4}, {'id':5, 'var1':'b', 'var2':'right', 'var3':0.1, 'var4':5}, {'id':5, 'var1':'b', 'var2':'right', 'var3':0.4, 'var4':2}] Then i can use the following function...

Make a list of values that belong to each region

Image
Clash Royale CLAN TAG #URR8PPP Make a list of values that belong to each region I have a little trouble in R. I'm pretty new R users. So I have a dataframe which looks like that (but much more longer) : My first problem is that my file have no header, I upload my file with this command : My_data=read.table("/home/toto/test.bed",sep="t", dec=".",fill=TRUE,header = FALSE) And after try to make a header like that names(My_data)=c("chr", "start","end","Region_type","Region_id") But when I want to take a column My_column<-My_data$Region_type It does not work. So I must to do like that : My_column<-My_data[,4] But I don't understand why the header doesn't work... My second problem is that I'm trying to make a list of all the clones (clone is represented by chrX Start-End) that belong to each region (MACS_peak_xxx). To do this I tried something like that : region_list <- levels(My_data[,4]...

How to convert List of Dictionary to simple 2D list in python to perform the specific task?

Image
Clash Royale CLAN TAG #URR8PPP How to convert List of Dictionary to simple 2D list in python to perform the specific task? I have a list which looks something like this : myList = [{'email_address': 'abc@gmail.com', 'status': 'subscribed'}, {'email_address': 'def@live.com', 'status': 'subscribed'}, {'email_address': 'ghi@gmail.in', 'status': 'pending'}, {'email_address': 'jkl@gmail.com', 'status': 'subscribed'}, {'email_address': 'mno@gmail.com', 'status': 'pending'}, {'email_address': 'pqr@yahoo.com', 'status': 'pending'}, {'email_address': 'stu@gmail.com', 'status': 'pending'}, {'email_address': 'vwx@y.com', 'status': 'pending'}, {'email_address': 'yz@z.com', 'status': 'pending'}] I want to convert th...

How To Compare Two Lists Using Regex?

Image
Clash Royale CLAN TAG #URR8PPP How To Compare Two Lists Using Regex? I Have Two Lists, 1. List<string>IDList //DM-0016 (ID:225),LPG Test (ID:232), 18S1(ID:290).. 2 List<string>Names // DM-0016,LPG Test, 18S1.. List<string>IDList //DM-0016 (ID:225),LPG Test (ID:232), 18S1(ID:290).. List<string>Names // DM-0016,LPG Test, 18S1.. The Second List is basically the same as the First but it doesn't have the IDs. I am Showing the Second List in a Multiple Choice Dialog, Where, user can select multiple items. I have a Regular Expression (@"(?<=(ID:)[0-9]+"); This returns only the the number inside (ID:) I want to compare these two Lists based on this RegEX, Where, I want only the ID's of the selected items. (@"(?<=(ID:)[0-9]+"); For Ex: If DM-0061 is selected i'll get 225 like so. what have you tried so far – Lucifer 6 mins ago ...