I'm working with a pretty large list and I need to separate the list from lst[7] and up. How do I go about this? Here's the code / lists specifically (My apologies for not formatting the list in the code snippet way, this was a lot easier to read this way):
Judging by your list, looks like everything you want will have 'year' as part of it's first element.
So do this:
your_new_list = [l for l in lst if 'year' in l[0]]
your_new_list will be a list of list that only the list that you want.
This will filter for all the list in your list of list where the first element has 'year' in the string.
You just need the 7th elements and up from this list? I can't fully understand your last line. But if that's the case:
lst2 = lst1[7:]
edit:
It actually looks like you want to skip the first nine lists, though, so it should be:
lst2 = lst1[9:]
Related
I'm trying to write a cell formula which can essentially create a single playlist of songs.
Currently the songs are grouped by decade, but I'd like to be able to see a single list of everything that has been ticked.
I tried an array formula, but it only returned the first ticked song. Plus not sure how to make the array formula include the adjacent lists.
I tried a FILTER function, it works for one list of songs, but I don't know how to get it to append the other lists on the end.
Could I use a QUERY function? Not sure how though.
Many thanks!
try:
={"LIST"; FILTER({C:C; F:F}; {B:B; E:E}=TRUE)}
awesome question! You were super close in your filter example, one more filter in your array would've done it :)
Example Image:
Example Formula:
={"LIST"; FILTER(C:C, B:B=TRUE); FILTER(F:F, E:E=TRUE)}
I have one generic list , from which I want to get those items only which are starting between some alphabets.
Supoose I have listitems like ABC,DEF,Zebra,Important,Check,Jump
From this I want to get listitem which starts from alphabet between A to C
This should return ABC,Check only..
Thanking in advance.
List stringlist= new List() {"ABC","BCD", "CDE","DEF","EFG","PQR","IJK","QRS","XYZ"};
List temp=stringlist.FindAll(s=>Enumerable.Range(65,3).Contains(s.toUpper()[0]));
change the range as per your requirement.
I have been learning VB for 4 weeks now and I have hit the limits of my knowledge. I sure could use some help from the more experienced programmers!!
Im trying to loop thru my list box and remove the first 4 chars of each line item.
specifically I would like it to behave like this:
first line of list box is selected and sent to string (minus 1st 4 chars)
first line of list box is removed from list box
modified version of first line of list box is added to list box in same position as original
next line of list box is selected...etc....
repeat until entire list box has been modified
Here is a sample of how I'm trying to do this....it almost works :)
Dim test As String
test = ListBox1.SelectedItem.ToString.Substring(4)
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
ListBox1.Items.Add(test)
can someone fill in the blanks for me?
Thanks in advance for your help
First, just to double check, you are looping through right?
Next, we can take a look at this line:
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) ListBox1.Items.Add(test)
If I understand this right, you're removing the item at a specific index, then you're adding the new string, test, back into the list. Looking at this, http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.objectcollection.add.aspx, it seems that add will stick this item at the end of the listbox, but you're removing something at a specified index.
Therefore, you're not actually replacing what you probably think you're replacing. That's my best guess. For example, if you remove the 2nd element in your list, but you when you put test back into the list, it's being added onto the end. So something like [a,b,c,d] becomes [a,c,d,b]
Perhaps changing that to:
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) ListBox1.Items.Insert(ListBox1.SelectedIndex, test)
ListBox items can be accessed and edited in this way..
listBox1.BeginUpdate();
try {
for(int i = listBox1.Items.Count - 1; i >= 0 ; i--) {
// do with listBox1.Items[i]
}
} finally {
listBox1.EndUpdate();
}
This is/isn't homework...the printing of the list IS homework and that works great, the iscntrl() and Array stuff is 6 weeks from now stuff and giving me grief.
I want to create an array filled with the first 32 TLAs of the Ascii table so that when I print out a column / row chart of Decimal to Ascii code I can use iscntrl() to flag that it's an un-printable character. In its place I want to grab the next TLA in the array and print that instead of the non-graphical character.
I have the iscntrl() working fine. Just can't figure out the array thing. All the examples in the books I have and online want to demo grabbing input from the user and tossing it into the array. I want to give the array a list at the beginning in the code and pull from that.
Can someone either give me a good link for what I need or just tell me how to do the whole process?
I've got 32 three letter items and I need to populate the array and pull them out via a for loop.
Thanks.
You can declare an array like this, and pre-fill its values:
const char *ControlCharacterNames[] = {
"NUL",
"SOH",
"STX",
"ETX",
// etc
};
Then, you can access ControlCharacterNames as an array in your code.
http://publications.gbdirect.co.uk/c_book/chapter6/initialization.html, chapter "6.7.2. More initialization".
Long story short, you probably need something like
char *TLAs[] = { "TL1", "TL2", "TL3", "FYI", "WTH", /* ...and so on...*/ };
and then pull the one you need using it's index
printf(TLAs[3]); // print "FYI", the 4th TLA
Hope I understood your question right.
I'm trying to make a link list and I'm having trouble with the concept with linking the middle part, I'm just doing a little pseudo-code right now, haven't actually coded anything.
(struct pointers) *current, *ahead, *behind, *begin;
(behind)-->(current)-->(ahead) //This is what I want to do
behind->next = current;
current->next = ahead;
Is this the proper way to break and connect the list? Without losing anything..
What you have looks correct but rather incomplete. One of the unwritten rules of programming is that you cannot write a linked list implementation correctly the first time. There are four cases you need to deal with:
Insert into an empty list
Insert into a non-empty list
Removing the first element from the list
Removing any other element from the list
There are also doubly-linked lists, where each element has a pointer to both the previous element and the next element. That makes it easier to handle things like removal of a random element without traversing the list, but can be trickier to get right.