Python Forum
Why can't I force an int to be a string?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why can't I force an int to be a string?
#1
It just doesn't work. I am familiar with str(10).

Here is my code. This is driving me crazy.

#Inputs
b = " is awesome"
c = 10
list1 =[]
output_dict={}
input_list = ['mike', 1, 'leon', 2, 'david', 3]

#Function
def listed(a):
    if "str" in str(type(a)):
        d = a + b
        return (d)
    else:
        e = a + c
        str(e)
        print (type (e))
        return (e)

#
for x in input_list:
    list1=listed(x)
#     list(list1)
#     print (type (list1))
#     # output_dict=zip(list1, input_list)
#     # print
It just returns class int and because of that I am not able to use the zip function later on.
Reply
#2
you are asking for the type of e
print (type (e))
if you want to print 'e', it's just:
print(e)
Reply
#3
I want E to be string instead of a integer so that list1 can be used in zip otherwise I get:

File "C:/Users/c0unt3rpl4y/PycharmProjects/House/Challenges/Archive/Challenge 6.py", line 52, in <module>
list(list1)
TypeError: 'int' object is not iterable

That is with me trying to use the list command on list1.

If I remove that (turning list1 into a list) which was my other try I get:

output_dict=zip(list1, input_list)
TypeError: zip argument #1 must support iteration

Basically I need the result of E to become a string so that i can use it in zip later.
Reply
#4
need to also change:
str(e)
to
e = str(e)
Reply
#5
You're a genius Larz. Thank you buddy.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Brute force for CTF (easy one) JokerTux 1 2,292 Feb-18-2020, 08:05 PM
Last Post: JokerTux
  Brute force password breaker Truman 7 4,373 Jan-23-2019, 01:00 AM
Last Post: Truman
  brute force skriff 4 3,807 Sep-12-2017, 06:23 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020