enumerate

Enumerate items in a list so a user can select the numeric value

邮差的信 提交于 2019-12-23 22:58:00
问题 I'm trying to find the most straightforward way to enumerate items in a list so that a user will not be burdened to type a long file name on a command line. The function below shows a user all .tgz and .tar files in a folder ... the user is then allowed to enter the name of the file he wants to extract. This is tedious and syntax-error prone for the user. I would like for a user to just select, say, a numeric value associated with the file (eg.. 1, 2, 3 etc.). Can someone give me some

Iterating through a character/string array in LaTeX

拟墨画扇 提交于 2019-12-23 08:43:06
问题 This is a continuation of my question posted earlier (Outputting character string elements neatly in Sweave in R). I have an array of strings, and am trying to output each element into LaTeX. I am able to achieve that using the following code: \documentclass[12pt,english,nohyper]{tufte-handout} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{longtable} \usepackage{wrapfig} \usepackaage{hyperref} \usepackage{graphicx} \usepackage[space]{grffile} \usepackage{geometry}

Reference list index to enumerate value

℡╲_俬逩灬. 提交于 2019-12-23 06:08:04
问题 I have a program which checks an outlook inbox for attachments from specific senders in a dictionary. Python - Outlook search emails within specific range only That program works fine, and now I'm trying to expand on it by giving the user the ability to choose a specific sender from the dictionary, so as to only search their emails. This code is within the previous program. The dictionary I have is senderDict = {sender@address.com : Sender Name} To turn it into a menu of values to choose from

Enumerating tables used in mysql query?

五迷三道 提交于 2019-12-22 00:15:46
问题 Is there any way to enumerate tables used in mysql query? Lets say I have query : SELECT * FROM db_people.people_facts pf INNER JOIN db_system.connections sm ON sm.source_id = pf.object_id INNER JOIN db_people.people p ON sm.target_id = p.object_id ORDER BY pf.object_id DESC And I want in return array: $tables = array( [0] => 'db_people.people_facts', [1] => 'db_system.connections', [2] => 'db_people.people', ); 回答1: The solution marked as good will return only the result tables. But if you

VB 6 How to make Custom Collection Class to support For Each

眉间皱痕 提交于 2019-12-21 04:03:16
问题 I've been placed on a project whose client front end is written in VB 6, ack! I'm trying to develop a custom collection class that supports the For...Each syntax. Is this possible in VB 6? Or am I stuck with using the For..Next with counter to identify the index. Thanks for the help! 回答1: The key part is adding this to the custom collection class... Public Function NewEnum() As IUnknown Set NewEnum = m_Employees.[_NewEnum] End Function and in the procedure attributes, set the procedure id to

How to use enumerate in this program?

谁都会走 提交于 2019-12-20 06:49:16
问题 f=open('Student.dat','r+') # opens Student.dat file roll1=input("Enter roll to be found") # to find a record in a list using a roll no rec=f.readlines() for i,lst in enumerate(rec): if lst == roll1: print rec[i] Is this the proper way to use enumerate?? or should i use another loop within?? 回答1: Here enumerate doesn't help much; you could use instead (which would be simpler and clearer): for i in rec: if i == roll1: print i enumerate is useful when you really need to get at the same time

Zip or enumerate in R?

a 夏天 提交于 2019-12-18 10:04:37
问题 What are the R equivalents for these Python list comprehensions: [(i,j) for i,j in zip(index, Values)] [(i,j) for i,j in enumerate(Values)] [(i,j) for i,j in enumerate(range(10,20))] %MWE, indexing or enumerating to %keep up with the index, there may %be some parameter to look this up Example with Output >>> [(i,j) for i,j in enumerate(range(10,20))] [(0, 10), (1, 11), (2, 12), (3, 13), (4, 14), (5, 15), (6, 16), (7, 17), (8, 18), (9, 19)] I have solved this problem earlier with some trick in

Is there an equivalent to the range-based `enumerate` loop from python in modern C++?

送分小仙女□ 提交于 2019-12-18 08:32:42
问题 Is there an equivalent to the range-based enumerate loop from python in C++? I would imagine something like this. enumerateLoop (auto counter, auto el, container) { charges.at(counter) = el[0]; aa.at(counter) = el[1]; } Can this be done with templates or macros? I'm aware that I can just use an old school for-loop and iterate until I reach container.size() . But I'm interested how this would be solved using templates or macros. EDIT I played a bit with boost iterators after the hint in the

pylint: Using possibly undefined loop variable 'n'

Deadly 提交于 2019-12-14 03:45:16
问题 Pylint say W: 6: Using possibly undefined loop variable 'n' with this code: iterator = (i*i for i in range(100) if i % 3 == 0) for n, i in enumerate(iterator): do_something(i) print n because if the iterator is empty (for example []) n is undefined, ok. But I like this trick. How to use it in a safe way? I think that using len(list(iterator)) is not the best choice because you have to do two loops. Using a counter, and incrementing it I think it's not very pythonic. 回答1: Have you considered

How to decode binary file with “ for index, line in enumerate(file)”?

我怕爱的太早我们不能终老 提交于 2019-12-13 09:33:51
问题 I am opening up an extremely large binary file I am opening in Python 3.5 in file1.py : with open(pathname, 'rb') as file: for i, line in enumerate(file): # parsing here However, I naturally get an error because I am reading the file in binary mode and then creating a list of bytes. Then with a for loop, you are comparing string to bytes and here the code fails. If I was reading in individual lines, I would do this: with open(fname, 'rb') as f: lines = [x.decode('utf8').strip() for x in f