Tkinter: Adding a entry at index 3 without there being one at index 1 or 2 - python-2.7

The problem im getting is if type something in my entry box it first fills index 1 and 2 of the listbox before finally typing into the 3rd index.
def country_get(event):
listbox.delete(3)
listbox.insert(3, country_label.cget('text') + event.widget.get() + '\n')
title_text=StringVar()
entry_country=Entry(master, bg="wheat3", fg="dark slate gray", textvariable=title_text)
entry_country.bind('<KeyRelease>', country_get)
entry_country.grid(row=4, column=1)
I want to be able to type at any index of the listbox whether it be the 3rd or 5th, without having anything at the previous index's.

You can't do what you want. The listbox isn't designed to have empty rows. If you want empty rows, you will need to insert empty strings.

Depending on how many entries I'm using or need, i just insert empty strings like so:
listbox.insert(0, "")
listbox.insert(1, "")
listbox.insert(2, "")
listbox.insert(3, "")
listbox.insert(4, "")
It appears that the listbox is empty when it fact it is just filled with empty strings. There are most likely other ways to get around this, but for what I need my program to do, this is what worked for me.

Related

How to extract a column based on it's content in PowerBI

I have a column in my table which looks like below.
ResourceIdentifier
------------------
arn:aws:ec2:us-east-1:7XXXXXX1:instance/i-09TYTYTY79716
arn:aws:glue:us-east-1:5XXXXXX85:devEndpoint/etl-endpoint
i-075656565f7fea3
i-02c3434343f22
qa-271111145-us-east-1-raw
prod-95756565631-us-east-1-raw
prod-957454551631-us-east-1-isin-repository
i-02XXXXXXf0
I want a new column called 'Trimmed Resource Identifier' which looks at ResourceIdentifier and if the value starts with "arn", then returns value after last "/", else returns the whole string.
For eg.
arn:aws:ec2:us-east-1:7XXXXXX1:instance/i-09TYTYTY79716  ---> i-09TYTYTY797168
i-02XXXXXXf0 --> i-02XXXXXXf0
How do I do this ? I tried creating a new column called "first 3 letters" by extracting first 3 letters of the ResourceIdentifier column but I am getting stuck at the step of adding conditional column. Please see the image below.
Is there a way I can do all of this in one step using DAX instead of creating a new intermediate column ?
Many Thanks
The GUI is too simple to do exactly what you want but go ahead and use it to create the next step, which we can then modify to work properly.
Filling out the GUI like this
will produce a line of code that looks like this (turn on the Formula Bar under the View tab in the query editor if you don't see this formula).
= Table.AddColumn(#"Name of Previous Step Here", "Custom",
each if Text.StartsWith([ResourceIdentifier], "arn") then "output" else [ResourceIdentifier])
The first three letters bit is already handled with the operator I chose, so all that remains is to change the "output" placeholder to what we actually want. There's a handy Text.AfterDelimiter function we can use for this.
Text.AfterDelimiter([ResourceIdentifier], "/", {0, RelativePosition.FromEnd})
This tells it to take the text after the first / (starting from the end). Replace "output" with this expression and you should be good to go.

How to create new column that parses correct values from a row to a list

I am struggling on creating a formula with Power Bi that would split a single rows value into a list of values that i want.
So I have a column that is called ID and it has values such as:
"ID001122, ID223344" or "IRRELEVANT TEXT ID112233, MORE IRRELEVANT;ID223344 TEXT"
What is important is to save the ID and 6 numbers after it. The first example would turn into a list like this: {"ID001122","ID223344"}. The second example would look exactly the same but it would just parse all the irrelevant text from between.
I was looking for some type of an loop formula where you could use the text find function to find ID starting point and use middle function to extract 8 characters from the start but I had no progress in finding such. I tried making lists from comma separator but I noticed that not all rows had commas to separate IDs.
The end results would be that the original value is on one column next to the list of parsed values which then could be expanded to new rows.
ID Parsed ID
"Random ID123456, Text;ID23456" List {"ID123456","ID23456"}
Any of you have former experience?
Hey I found the answer by myself using a good article similar to my problem.
Here is my solution without any further text parsing which i can do later on.
each let
PosList = Text.PositionOf([ID],"ID",Occurrence.All),
List = List.Transform(PosList, (x) => Text.Middle([ID],x,8))
in List
For example this would result "(ID343137,ID352973) ID358388" into {ID343137,ID352973,ID358388}
Ended up being easier than I thought. Suppose the solution relied again on the lists!

strings in a list not properly being added to an empty string

Im making a calculator program, and I'm currently trying to get the user's input into a string. I was able to create a list based on the buttons they pressed. So if they pressed 5, the string would be '5', and if they pressed 8 after, it would be '58', etc. So for each time the person presses the button, I have that number added to a list, so in the last example the list would be ['5','8']. Im trying to get those into a string together, '58', but am having issues.
from Tkinter import *
root=Tk()
root.geometry('300x500')
root.configure(bg="gray")
root.title("Calculator")
typed_num=[]
def button_command(number):
typed_num.append(str(number))
string_num=''
for val in typed_num:
string_num+=typed_num
print string_num
startx=20
starty=60
one_button=Button(root, text="1", command=lambda:button_command(1), highlightbackground='gray').place(x=startx, y=starty)
two_button=Button(root, text="2", command=lambda:button_command(2), highlightbackground='gray').place(x=startx+60, y=starty)
three_button=Button(root, text="3", command=lambda:button_command(3), highlightbackground='gray').place(x=startx+120, y=starty)
four_button=Button(root, text="4", command=lambda:button_command(4), highlightbackground='gray').place(x=startx, y=starty+60)
five_button=Button(root, text="5", command=lambda:button_command(5), highlightbackground='gray').place(x=startx+60, y=starty+60)
six_button=Button(root, text="6", command=lambda:button_command(6), highlightbackground='gray').place(x=startx+120, y=starty+60)
seven_button=Button(root, text="7", command=lambda:button_command(7), highlightbackground='gray').place(x=startx, y=starty+120)
eight_button=Button(root, text="8", command=lambda:button_command(8), highlightbackground='gray').place(x=startx+60, y=starty+120)
nine_button=Button(root, text="9", command=lambda:button_command(9), highlightbackground='gray').place(x=startx+120, y=starty+120)
zero_button=Button(root, text="0", command=lambda:button_command(0), highlightbackground='gray').place(x=startx+60, y=starty+180)
root.mainloop()
Any and all help is greatly appreciated! The error returned is:TypeError: cannot concatenate 'str' and 'list' objects
You are attempting this concatenation here: string_num+=typed_num. You can use append if you want to add an item to list such as typed_num.append(string_num). You tried to add a list to a string, you can add a string to a list however. "+" can be also used but the other way around
The problem is caused because you want to add a list with a string, that operation is not possible, I think you want to do is concatenate for them you must change:
string_num+=typed_num
to
string_num+=val
A simple way to concatenate a string list is to join, for this it changes:
string_num=''
for val in typed_num:
string_num+=typed_num
print string_num
to:
print "".join(typed_num)

How to manage looping on this list on Applscript?

The list is in the form of:-
0:
https://url
1:
https://url
..... And so on.
How could I loop on this list. So I could fetch the number first without ":" and type it somewhere then fetch the url that comes after that number and type it elsewhere. Then end repeat if the list is over.
Or should I use records instead?
I am still a beginner using AppleScript. I tried many commands I mixed up but the computer keeps running the script nonestop and the activity monitor shows the applescript using 100% of the processor and huge amount of ram.
Appreciate any help.
Thank you
You didn't define what your list really looks like very well so I made an assumption on my answer below. If I was wrong, hopefully my answer will at least point you in the right direction. (or if I've gotten it wrong, but you can choose to reformat it to the way I suggested, that could still help)
on run
set theList to {"0:http://apple.com", "1:http://google.com"} -- my guess at what your list looks like.
repeat with anItem in theList
set anItem to anItem as string
set itemParts to myParseItem(anItem)
set tID to the_integer of itemParts as integer
set tURL to the_url of itemParts as string
end repeat
end run
on myParseItem(theItem)
set AppleScript's text item delimiters to ":"
set delimitedList to every text item of theItem
set newString to (items 2 thru -1 of delimitedList as string)
set AppleScript's text item delimiters to {""}
set theInt to item 1 of delimitedList
set theURL to newString as string
return {the_integer:theInt, the_url:theURL}
end myParseItem

Match multiple strings using re.search within an if condition

I am writing a program to create a list from a spreadsheet based on a position value in another cell. So my code looks like
for j in xrange(1,13):
for sheet in wb.sheets():
for i in xrange(1,12*15):
team=sheet.cell(i,0)
position=sheet.cell(i,2)
games=sheet.cell(i,23)
if re.match(owner[j], str(team.value)) and (not re.findall('Defense' or 'K,' or 'KFG' or 'KKO', str(position.value))):
try:
list.append(int(games.value))
except ValueError:
list.append(0)
else:
pass
print list
list=[]
So the goal of this is to append to a list when a row matches owner in the first column, and not Defense K, KFG KKO in the position column.
Unfortunately, the values for K, KFG and KKO all show
up in my lists, but the Defense values properly do not. How can I
ensure the other filtering criteria are met?
As a side note, these positions are in amongst other bits of text so
the search() is used here instead of match().
"Defense" is a 'truthy' value, so the result of:
'Defense' or 'K,' or 'KFG' or 'KKO'
is 'Defense'.
Therefore, the condition you have is no different from:
re.match(owner[j], str(team.value)) and (not re.findall('Defense', str(position.value)))
If you want alternatives in a regex, use | in the pattern:
re.match(owner[j], str(team.value)) and (not re.findall('Defense|K,|KFG|KKO', str(position.value)))