If I have this:
def array = [1,2,3,4,5,6]
Is there some built-in which allows me to do this ( or something similar ):
array.split(2)
and get:
[[1,2],[3,4],[5,6]]
?
Actually i have extracted some data from the file and want to write it in the file 2 but the program says 'sequence item 1: expected string, list found', I want to know how i can convert buffer[] ie string into sequence, so that it could be saved in file 2...I am new to the python please help*
file = open('/ddfs/user/data/k/ktrip_01/hmm.txt','r')
file2 = open('/ddfs/user/data/k/ktrip_01/hmm_write.txt','w')
buffer = []
rec = file.readlines()
for line in rec :
field = line.split()
print '>',field[0]
term = field[0]
buffer.append(term)
print field[1], field[2], field[6], field[12]
term1 = field [1]
buffer.append(term1)
term2 = field[2]
buffer.append[term2]
term3 = field[6]
buffer.append[term3]
term4 = field[12]
buffer.append[term4]
file2.write(buffer)
file.close()
file2.close()
I've been coding for quite sometime now. And my work pertains to solving real-world business scenarios. However, I have not really come across any practical usage of some of the data structures like the LinkedList, Queues and Stacks etc.
Not even at the business framework level. Of course, there is the ubiquitous HashTable, ArrayList and of late the List...but is there any practical usage of some of the other basic data structures?
It would be great if someone gave a real-world solution where a Doubly LinkedList "performs" better than the obvious easily usable counterpart.
I have the following java code:
import java.util.Arrays;
import java.util.Collections;
public class Test {
public static void main(String[] args) {
int[] test = {1,2,3,4,5};
Collections.rotate(Arrays.asList(test), -1);
for(int i = 0; i < test.length; i++) { System.out.println(test[i]); }
}
}
I want the array to be rotated, but the output I get is
1
2
3
4
5
Why is this?
And is there an alternative solution?
I'm iterating through the controls in a dialog and I'm trying to determine if a combobox was created with the WS_VSCROLL style.
The style, obtained from GetWindowLong(hwnd, GWL_STYLE), doesn't contain the WS_VSCROLL bit (0x200000), even when I know it was set on create.
Clarification: I am looking to see if the ComboBox was created with the WS_VSCROLL style. Calling GetWindowLong() (or using spy++) to get the style of the combo's listbox will include WS_VSCROLL if a scrollbar is needed to based on the current contents of the list.
I am trying to determine if the ComboBox was created with WS_VSCROLL, not if a scrollbar is currently visible.
<ul>
<li><a href="#">one</a></li>
<li><a href="#">two</a></li>
<li><a href="#">three</a></li>
</ul>
I'd like to show only one li at a time using slide effect, thats it. I'd like to avoid using plugins for something as simple as this.
Thanks in advance for your help.
I'm trying to transfer the contents of one list to another, but it's not working and I don't know why not. My code looks like this:
list1 = [1, 2, 3, 4, 5, 6]
list2 = []
for item in list1:
list2.append(item)
list1.remove(item)
But if I run it my output looks like this:
>>> list1
[2, 4, 6]
>>> list2
[1, 3, 5]
My question is threefold, I guess: Why is this happening, how do I make it work, and am I overlooking an incredibly simple solution like a 'move' statement or something?
hi. my tool is in asp. i am using this code for a query in sql
dim req_id
req_id=Request.Form("Req_id")
if req_id<>"" then
Set conn=server.CreateObject("adodb.connection")
conn.Open session("Psrconnect")
Set rs=CreateObject("Adodb.Recordset")
rs.Open "select * from passwords where REQ_ID='"&req_id&"'", conn
i want to put the results of this query into a drop down list. how do i do it? any help is very much appreciated.
I've found an old plugin called acts_as_habtm_list - but it's for Rails 1.0.0.
Is this functionality built in acts_as_list now? I can't seem to find any information on it.
Basically, I have an artists_events table - no model. The relationship is handled through those two models specifying :has_and_belongs_to_many
How can I specify order in this situation?
I currently have an array of around 8 - 10 numbers that changes on a periodic basis.
So around every 5 - 10 seconds the numbers get updated.
I need to get the top 3 numbers in the array every 10 seconds.
This is all done on a mobile device.
At the minute I iterate through the array 3 times and each time I take out the three highest numbers and place them in three previously declared variables.
My question is what should I look to do to increase speed and efficiency in this instance?
public static IQueryable<Institution> WithFunds(this IQueryable<Institution> query, IEnumerable<Fund> allowedFunds)
{
return query.
}
I want to get the query to return all Institutions having any of the Fund given in 'allowedFunds' list in Institution.Funds. Please help.
My class hierarchy goes like this.
public partial class Institution
{
public int Id { get; set; }
public virtual ICollection<Fund> Funds { get; set; }
}
public partial class Fund
{
public int Id { get; set; }
public virtual Institution Institution { get; set; }
}
i've a list of items from a query to database. Now i want to display them to user via HTML.
My initial way is like this:
<ol>
<li>
search element 1
</li>
...
</ol>
I'm wondering if there is a better semantic way with HTML5 like:
<article>
<section>
search element 1
</section>
...
</article
Does anyone have a better semantic way?
I gonna try to describe my problem the best i can. I have two lists, one with audio frames and other with color frames (not relevant). Both of them have timestamps, they were captured at the same moment but at different instants. So, i have like this:
index COLOR AUDIO
0 841 846
1 873 897
2 905 948
3 940 1000
the frames start at high numbers because they were captured and then trimmed to specific parts, but im shot, frame 0 is synced with only 5ms apart(timestamp in ms).
On every case i have, the audio frames count is less than the color count. I need to make them have the same count. The stating frames may be coloraudio, color
How can I generate all the possible sets of the elements of a list with current length?
get_set(X, [1,2,3]).
X = [1,1,1],
X = [1,1,2],
X = [1,1,3],
X = [1,2,1],
X = [1,2,2],
X = [1,2,3],
X = [1,3,1],
X = [1,3,2],
X = [1,3,3],
.....
X = [3,3,2],
X = [3,3,3].
UPD: there is good answer given by Sharky.
But maybe it's not the best. Here is another:
get_set(X,L) :- get_set(X,L,L).
get_set([],_).
get_set([X|Xs],[_|T],L) :- member(X,L), get_set(Xs,T,L).
I guess this is trivial, I apologize, I couldn't find how to do it.
I am trying to abstain from a loop, so I am trying to vectorize the process:
I need to do something like grep, but where the pattern is a vector. Another option is a match, where the value is not only the first location.
For example data (which is not how the real data is, otherswise I would exploit it structure):
COUNTRIES=c("Austria","Belgium","Denmark","France","Germany",
"Ireland","Italy","Luxembourg","Netherlands",
"Portugal","Sweden","Spain","Finland","United Kingdom")
COUNTRIES_Target=rep(COUNTRIES,times=4066)
COUNTRIES_Origin=rep(COUNTRIES,each=4066)
Now, currently I got a loop that:
var_pointer=list()
for (i in 1:length(COUNTRIES_Origin))
{
var_pointer[[i]]=which(COUNTRIES_Origin[i]==COUNTRS_Target)
}
The problem with match is that match(x=COUNTRIES_Origin,table=COUNTRIES_Target) returns a vector of the same length as COUNTRIES_Origin and the value is the first match, while I need all of them.
The issue with grep is that grep(pattern=COUNTRIES_Origin,x=COUNTRIES_Target) is the given warning:
Warning message:
In grep(pattern = COUNTRIES_Origin, x = COUNTRIES_Target) :
argument 'pattern' has length > 1 and only the first element will be used
Any suggestions?
Hi All
I need something like a Dictionary or a SortedList but i keep getting exceptions thrown when it receives two things that are the same... Is there another way around this?
Thanks
I want to display about 20 li on a page with a link at the bottom that says something like 'display more'. This link will then clear the first 20 and display the next 20. How should i go about doing this. (I am creating a gallery)
I was thinking about using PHP and MySQL. However for what I am doing I do not really need to store it in a database so is there an easier way of doing it only using html, php or javascript?
thanks
When I type a URL into an email in Outlook, it automatically converts it to a hyperlink. I can, of course, remove the hyperlink from the context menu:
But, then when the email is received and when I view it in my Sent Items folder, the urls are again converted to hyperlinks. How can I prevent this? Embedded images are no good because the URL must be copy and pasteable (among numerous other reasons that this approach is not great). And it must retain the formatting applied when I send it.
This answer on stackoverflow shows a good trick for preventing auto linked urls when sending an email programmatically, but I'm looking for a way to do this from the UI. Perhaps there a way to edit the HTML of the message before it is sent?
If not, I guess I'm off to write an Outlook Add-in.
I have a shell account where I am not allowed to compile anything.
There are however tools I need to run, some very simple ones like Midnight Commander, mcedit, most, jed
I am trying to find a staically linked version that "just works" in my shell.
Could anyone give me any advice on where I could find statically builds? I have not been able to find it with google.
I could compile it myself, but I would have to find out which headers I need to compile for. I have never tried to do it before, so any help would be greatly apprechiated!
My host uses CloudLinux, output of uname -a:
Linux hostname.domain.com 2.6.18-408.el5.lve0.8.61.1 #1 SMP Wed Apr 18 07:47:15 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux
Since a short while I'm using Ubuntu Oneiric Ocelot (11.10) with gnome-shell (Gnome 3) and I'm trying to get accustomed to the default Empathy Instant Messaging client.
When I hit the close button of Empathy's contact list the window disappears as expected. When I now start Empathy over the Gnome Activities menu the contact list reappears. That's not as easy as clicking a system tray icon back in Psi on Gnome 2 but it works for now.
But when I start a conversation first and have an open conversation window, then close the contact list, and try to regain access to it by using Gnome Activities, I only get the conversation window into focus and no contact list appears. I only seem to be able to get the contact list back if I close the conversation window (and thereby signal the conversations to be over) and then use Gnome Activities again to get my contact list back.
That's horrible. Is this intended? Is there something I'm missing?
After more than a few questions about deciding on C++ books I thought we could make a better community wiki version. Providing QUALITY books and an approximate skill level. Maybe we can add a short blurb/description about each book that you have personally read / benefited from. Feel free to debate quality, headings, etc.
Note: There is a similar post for C: The Definitive C Book Guide and List
Reference Style - All Levels
The C++ Programming Language - Bjarne Stroustrup
C++ Standard Library Tutorial and Reference - Nicolai Josuttis
Beginner
Introductory:
C++ Primer - Stanley Lippman / Josée Lajoie / Barbara E. Moo
Accelerated C++ - Andrew Koenig / Barbara Moo
Thinking in C++ - Bruce Eckel (2 volumes, 2nd is more about standard library, but still very good)
Best practices:
Effective C++ - Scott Meyers
Effective STL - Scott Meyers
Intermediate
More Effective C++ - Scott Meyers
Exceptional C++ - Herb Sutter
More Exceptional C++ - Herb Sutter
C++ Coding Standards: 101 Rules, Guidelines, and Best Practices - Herb Sutter / Andrei Alexandrescu
C++ Templates The Complete Guide - David Vandevoorde / Nicolai M. Josuttis
Large Scale C++ Software Design - John Lakos
Above Intermediate
Modern C++ Design - Andrei Alexandrescu
C++ Template Metaprogramming - David Abrahams and Aleksey Gurtovoy
Inside the C++ Object Model - Stanley Lippman
Classics / Older
Note: Some information contained within these books may not be up to date and no longer considered best practice.
The Design and Evolution of C++ - Bjarne Stroustrup
Ruminations on C++ Andrew Koenig / Barbara Moo
Advanced C++ Programming Styles and Idioms - James Coplien
I am trying to delete a file from SharePoint using the list web service which is failing with the following error.
Error Code: 0x81020030
Message: Invalid file name
Detail: The file name you specified could not be used. It may be the name of an existing file or directory, or you may not have permission to access the file.
The update XML I sent through is:
<Batch OnError="Continue" PreCalc="TRUE" ListVersion="0" ViewName="{8FE4E2C8-939E-4462-ABA2-D633EED7F76E}"><Method ID="1" Cmd="Delete"><Field Name="ID">84</Field><Field Name="FileRef">http://win-4h0xp59sn75:40414/Shared%20Documents/del.txt</Field></Method></Batch>
The SharePoint server error logs indicate:
ERROR: Failed to OpenThreadToken,
LastError=1008
The file you are
attempting to save or retrieve has
been blocked from this Web site by
the server administrators.
Things I have tried
I've tried the changes in
#1372971 which has no helped.
I
have also tried the changes
recommended on the Microsoft Social
site, which has also not helped.
I have confirmed that the txt file
extension is not blocked as indicated
here. In addition I can remove
the file via the website, it is just
on the web service that this fails.
The permissions are correct (or rather not in play) as I am running as a SharePoint administrator, which is the same account that uploaded it via the copy web service.